正常动态sql写法(if标签)
<select id="findActiveBlogWithTitleLike" resultType="Blog">
SELECT * FROM BLOG
WHERE state = ‘ACTIVE’
<if test="title != null">
AND title like #{title}
</if>
</select>
另一种写法(引入外部sql)
<select id="findActiveBlogWithTitleLike" resultType="Blog">
SELECT * FROM BLOG
<where>
//通过include 标签引入sql
<include refid="BuhinmtWhere" />
</where>
</select>
//额外的动态sql语句
<sql id="BuhinmtWhere">
<if test="title != null and title != ''">
AND title like #{title}
</if>
</sql>