if/where 标签
<!--根据性别和名字查询用户 where标签可以自动去掉第一个前and-->
<select id="selectUserBySexAndUsername" parameterType="pojo.User" resultType="pojo.User">
select * from user
<where>
<if test="sex!=null and sex!=''">
and sex = #{sex}
</if>
<if test="username != null and username !=''">
and username = #{username}
</if>
</where>
</select>
sql片段
<sql id="selector">
select * from user
</sql>
<include refid="selector"></include>
foreach
<!--多个id 传包装对象-->
<select id="selectUserByIds1" parameterType="pojo.QueryVo" resultType="pojo.User">
<include refid="selector"></include>
<where>
id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>
<!--多个id 传array或者list 注意collection要使用array或者list-->
<select id="selectUserByIds" parameterType="pojo.QueryVo" resultType="pojo.User">
<include refid="selector"></include>
<where>
id in
<foreach collection="array" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>