MyBatis动态sql中模糊查询
2017-11-14 14:24
627 查看
1、直接拼接%%:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != '%%'">
and frame_no like '%${frameNo}%'
</if>
</select>
2、定义 一个<bind/>变量:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
<bind name="frameNo" value="'%' + _parameter.frameNo + '%'" />
select <include refid="textDatas"/> from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != '%%'">
and frame_no like #{frameNo}
</if>
</select>
3、使用locate()函数:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != ''">
and LOCATE(#{frameNo}, frame_no ) > 0
</if>
</select>
4、使用instr()函数:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != ''">
and INSTR(frame_no , #{frameNo})
</if>
</select>
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != '%%'">
and frame_no like '%${frameNo}%'
</if>
</select>
2、定义 一个<bind/>变量:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
<bind name="frameNo" value="'%' + _parameter.frameNo + '%'" />
select <include refid="textDatas"/> from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != '%%'">
and frame_no like #{frameNo}
</if>
</select>
3、使用locate()函数:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != ''">
and LOCATE(#{frameNo}, frame_no ) > 0
</if>
</select>
4、使用instr()函数:
<select id="getActiveDatas" parameterType="java.util.Map" resultType="java.util.Map">
select * from tab_test where is_deleted = 0
<if test="frameNo != null and frameNo != ''">
and INSTR(frame_no , #{frameNo})
</if>
</select>
相关文章推荐
- mybatis 动态SQL与模糊查询
- Mybatis学习笔记-动态SQL和模糊查询
- 03. mybatis 动态sql && 模糊查询
- 【Mybatis学习总结六】动态SQL与模糊查询
- MyBatis的动态SQL的模糊查询
- Mybatis学习总结之动态SQL与模糊查询
- MyBatis笔记(九)——动态SQL与模糊查询
- Mybatis 模糊查询和动态sql语句
- 六、Mybatis动态SQL和模糊查询
- 利用mybatis的动态sql 进行批量模糊查询
- Mybatis之动态SQL 模糊查询
- MyBatis-动态sql与模糊查询 -07
- Mybatis学习----模糊查询和动态sql
- MyBatis入门07--实现sql动态模糊查询
- MyBatis笔记07 - 动态SQL与模糊查询
- Mybatis 1.动态sql 2.模糊查询
- mybatis的动态SQL与模糊查询
- MyBatis动态SQL与模糊查询
- myBatis学习笔记(6)——动态SQL & 模糊查询
- 【mybatis】动态SQL之模糊查询