【MyBatis】动态 SQL
转载:
目录
==========================================
1、if
2、choose when otherwise
3、trim where set
4、foreach
5、bind
==========================================
1、if
<select id="selectAuthor" resultType="Author"> select * from author where sex = 'male' <if test="name != null"> and name = #{name} </if> </select>
5、bind
基本参数
public List<Blog> selectBlogList(@Param("title") String title);
<select id="selectBlogList" resultType="Blog"> <bind name="titlePattern" value="'%' + title + '%'"/> select * from blog <where> <if test="title != null"> and title like #{titlePattern} </if> </where> </select>
对象参数
public List<Blog> selectBlogList(Blog blog);
<select id="selectBlogList" resultType="Blog"> <bind name="titlePattern" value="'%' + _parameter.getTitle() + '%'"/> select * from blog <where> <if test="title != null"> and title like #{titlePattern} </if> </where> </select>