<selectid="queryBlogIF"parameterType="map"resultType="blog">
select * from mybatis.blog where 1=1
<iftest="title != null">
and title = #{title}
</if><iftest="author != null">
and author = #{author}
</if></select>
2、choose (when, otherwise)
<selectid="queryBlogChoose"parameterType="map"resultType="blog">
select * from mybatis.blog
<where><choose><whentest="title != null">
title = #{title}
</when><whentest="author != null">
and author = #{author}
</when><otherwise>
and views = #{views}
</otherwise></choose></where></select>
3、trim (where,set)
select * from mybatis.blog
<where><iftest="title != null">
title = #{title}
</if><iftest="author != null">
and author = #{author}
</if></where>
<updateid="updateBlog"parameterType="map">
update mybatis.blog
<set><iftest="title != null">
title = #{title},
</if><iftest="author != null">
author = #{author}
</if></set>
where id = #{id}
</update>
4、foreach
<!--
select * from mybatis.blog where 1=1 and (id=1 or id = 2 or id=3)
我们现在传递一个万能的map , 这map中可以存在一个集合!
--><selectid="queryBlogForeach"parameterType="map"resultType="blog">
select * from mybatis.blog
<where><foreachcollection="ids"item="id"open="and ("close=")"separator="or">
id = #{id}
</foreach></where></select>