<!-- test里面放判断条件 --><iftest="id != null and id != -1">
WHERE id=#{id}
</if>
2.trim-if 多条件结构
<!-- prefix:条件前缀 prefixOverrides:前缀覆盖AND|OR --><trimprefix="WHERE"prefixOverrides="AND|OR"><iftest="id != null">
AND id=#{id}
</if><iftest="name != null">
AND userName like CONCAT('%',#{name},'%')
</if></trim>
3.where-if 多条件结构
<where><iftest="id != null">
AND id=#{id}
</if><iftest="name != null">
AND userName like CONCAT('%',#{name},'%')
</if></where>
4.choose-when-otherwise 多选一结构
<choose><whentest="id!=null">
WHERE id=#{id}
</when><whentest="name!=null">
WHERE userName like CONCAT('%',#{name},'%')
</when><otherwise><!-- 上面条件都不满足时执行 --></otherwise></choose>
5.foreach 循环结构 代替 WHERE id IN (?,?..)
WHERE id IN
<!-- collection:集合名称 item:每一个元素 open:sql开始部位 separator:中间分隔符 close:sql结束部位 --><foreachcollection="ids"item="id"open="("separator=","close=")">
#{id}
</foreach>