Mybatis中的like模糊查询功能

作者:袖梨 2022-06-25

1.  参数中直接加入%%

 代码如下 复制代码

param.setUsername("%CD%");

 param.setPassword("%11%");

select id,sex,age,username,password from person wheretrue

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(concat('%',#{username}),'%')

相关文章

精彩推荐