Mybatis做like模糊查询

mybatis在做Like的模糊查询的时候,不能直接在sql语句中使用like %关键词,因为这是Mybatis的保留关键字。其实想做模糊查询很简单,随便写下以下几种供大家参考:

1. 参数中直接加入%%

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

		select id,sex,age,username,password from person where true 
			 AND username LIKE #{username}
			AND password LIKE #{password}

2. bind标签

          select id,sex,age,username,password 
           from person
          where username LIKE #{pattern}

3. CONCAT

where username LIKE concat(cancat('%',#{username}),'%')


版权声明:本文为weixin_48456383原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。