set标签
<update id="blogUpDate" parameterType="map">
update mybatis.blog
<set>
<if test="title != null">
title = #{title},
</if>
<if test="author != null">
author = #{author}
</if>
</set>
where id = #{id}
</update>
Sql公共标签
<sql id="if-title-author">
<if test="title != null">
title = #{title}
</if>
<if test="author != null">
and author = #{author}
</if>
</sql>
<select id="blogSelectSql" parameterType="map" resultType="blog">
select * from mybatis.blog
<where>
<include refid="if-title-author"></include>
</where>
</select>
foreach
<!--SELECT * FROM blog where 1=1 AND (id = 1 or id = 2)-->
<select id="blogSelectForeach" parameterType="map" resultType="blog">
SELECT * FROM blog
<where>
<foreach collection="ids" item="id" open="AND (" close=")" separator="OR">
id = #{id}
</foreach>
</where>
</select>