1.if标签
2.where标签:可以自动处理下一个and
<select id="findUserByCondition" resultMap="userMap">
select * from user where 1=1
<where>
<if test="username != null">
AND username =#{username}
</if>
<if test="sex !=null">
and sex =#{sex}
</if>
</where>
</select>
SQL语句:select字段from user where id in(?)
标签用于遍历集合,它的属性:
collection:代表要遍历的集合元素,编写时不可写成#{}
open:代表语句的开始部分
close:代表语句的结束部分
item:代表遍历集合的每个元素,生成的变量名
sperator:代表分隔符
<select id="findUserInIds" resultMap="userMap" parameterType="queryvo">
<include refid="defaultUser"></include>
<where>
<if test="ids != null and ids.size()>0">
<foreach collection="ids" open="and id in (" close=")" item="uid" separator=",">
#{uid}
</foreach>
</if>
</where>
</select>