1
2 <!-- 查询用户信息 -->
3 <select id="queryUser3" parameterType="org.pine.mybatis.util.UserQueryBean" resultType="org.pine.mybatis.po.User">
4 select t.id,t.username,t.birthday,t.sex,t.address
5 from user t
6 <!--
7 where 元素只会在至少有一个子元素的条件返回 SQL 子句的情况下才去插入“WHERE”子句。(如果没有子元素的条件返回 SQL 子句,则不会插入“WHERE”子句)
8 而且,若语句的开头为“AND”或“OR”,where 元素也会将它们去除。
9 -->
10 <where>
11 <!-- _parameter:代表整个参数 -->
12 <if test="_parameter!=null">
13 <if test="username!=null and username!=''">
14 t.username like '%${username}%'
15 </if>
16 <if test="sex!=null and sex!=''">
17 and t.sex=#{sex}
18 </if>
19 </if>
20 </where>
21 </select>
22
23 <!-- 查询用户信息 -->
24 <select id="queryUser4" parameterType="org.pine.mybatis.util.UserQueryBean" resultType="org.pine.mybatis.po.User">
25 select t.id,t.username,t.birthday,t.sex,t.address
26 from user t
27 where 1=1
28 <!-- _parameter代表整个参数 -->
29 <if test="_parameter!=null">
30 <if test="username!=null and username!=''">
31 and t.username like '%${username}%'
32 </if>
33 <if test="sex!=null and sex!=''">
34 and t.sex = #{sex}
35 </if>
36 </if>
37 </select>