1.if label
Inside the test entity class is a property userName.
<!--根据条件查询--> <select id="findUserByConditon" resultMap="userMap" parameterType="user"> select * from user where 1=1 <if test="userName!=null"> and username=#{userName} </if> <if test="sex!=null"> and sex=#{sex} </if> </select>
2.where label're welcome where 1 = 1
<!--根据条件查询--> <select id="findUserByConditon" resultMap="userMap" parameterType="user"> select * from user <where> <if test="userName!=null"> and username=#{userName} </if> <if test="sex!=null"> and sex=#{sex} </if> </where> </select>
3.foreach label
open a (Close a) Item used per one separator ',' separated.
<!--根据queryVo中的id集合查询用户列表--> <select id="findUserInIds" resultMap="userMap" parameterType="queryVo"> select * from user <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>