Mybatis-Plus模糊查询(like)特殊字符_、\、%时的处理方式

一:直接定义函数进行处理

public static String escapeStr(String str) {
if (StringUtils.isEmpty(str)) {
str = str.replaceAll("\\\\", "\\\\\\\\");
str = str.replaceAll("_", "\\\\_");
str = str.replaceAll("%", "\\\\%");
}
return str;
}

 二:Mapper 中sql 处理

select * from staff where name like CONCAT('%', '%' , '%') escape '%';

 

posted @ 2021-08-13 11:52  唏嘘-  阅读(1824)  评论(0编辑  收藏  举报