您的位置:首页 > 数据库

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: