mybatis做like模糊查询
- 2020 年 4 月 2 日
- 筆記
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}),'%')