where
去除子句头部的or或者and
<select id="findActiveBlogLike"
resultType="Blog">
SELECT * FROM BLOG
<where>
<if test="state != null">
state = #{state}
</if>
<if test="title != null">
AND title like #{title}
</if>
</where>
</select>
set
去除子句尾部的逗号
<update id="updateAuthorIfNecessary">
update Author
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="bio != null">bio=#{bio}</if>
</set>
where id=#{id}
</update>
trim
定制标签元素。比如自定义set或者自定义where标签
//自定义where
<trim prefix="WHERE" prefixOverrides="AND |OR ">
...
</trim>
//自定义set
<trim prefix="SET" suffixOverrides=",">
...
</trim>
if,choose/when/otherwise
choose/when/otherwise等同于switch语句
foreach
集合遍历
<select id="selectPostIn" resultType="domain.blog.Post">
SELECT *
FROM POST P
WHERE ID in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>