<select id="findUserInfoByTrim" parameterType="Map"
resultMap="UserInfoResult">
select * from userinfo
<trim prefix="where" prefixOverrides="and|or">
<if test="department!=null">
AND department like #{department}
</if>
<if test="gender!=null">
AND gender=#{gender}
</if>
<if test="position!=null">
AND position like #{position}
</if>
</trim>
</select>
备注:
a.我们使用替代标签。
b.属性“prefix”表示:加入前缀where
c.属性“prefixOverrides”表示:自动覆盖第一个“and”或者“or”
d.后缀的用法类似;
<update id="updateUserInfoBySet" parameterType="userInfo">
update userInfo
<set>
<if test="mobile!=null">
mobile=#{mobile},
</if>
<if test="gender!=null">
gender=#{gender},
</if>
<if test="position!=null">
position = #{position},
</if>
</set>
where userid=#{userid}
</update>