0
点赞
收藏
分享

微信扫一扫

Mybatis用like进行模糊查询问题


Mybatis用like进行模糊查询的时候,配置与所用的数据库有关系,总结了下,具体如下:

1、直接在JAVA代码中做模糊拼接。(不做实例)

2. 使用bind标签


<select id="selectPersons" resultType="person" parameterType="person">
  <bind name="pattern" value="'%' + _parameter.username + '%'" />
  select id,sex,age,username,password 
  from person
  where username LIKE #{pattern}
</select>


3.使用数据拼接函数 CONCAT

3.1、mysql :LIKE CONCAT('%',#{empname},'%' ) 或者 LIKE CONCAT('%',‘${empname}’,'%' )

3.2、oracle:LIKE '%'||#{empname}||'%'

举报

相关推荐

0 条评论