欢迎您的访问
专注于分享最有价值的互联网技术干货

MyBatis做like模糊查询

几个T的资料等你来白嫖
双倍快乐
资源帮找!!!

这个网站中有很多方法。https://code.google.com/p/mybatis/issues/detail?id=85

自己试验了如下的方法。

1、参数中直接加入%%

param.setUsername("%CD%"); param.setPassword("%11%");

<select  id="selectPersons" resultType="person" parameterType="person">
        select id,sex,age,username,password from person where true 
            <if test="username!=null"> AND username LIKE #{username}</if>
            <if test="password!=null">AND password LIKE #{password}</if>

    </select>

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

where username LIKE concat(cancat('%',#{username}),'%')
赞(0) 打赏
版权归原创作者所有,任何形式转载请联系我们:大白菜博客 » MyBatis做like模糊查询

评论 抢沙发

8 + 1 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏