Mybatis plus中一个框多条件查询 SQL拼接

时间:2024-05-20 00:03:50

遇到多条件查询时,只用框架自带的方法搞不定,只能自己写方法拼接

EntityWrapper<YcejShopEntity> wrapper = new EntityWrapper<>();
String queryStr = QueryUtils.toFuzzyQueryStr(username.toString());
String filterSql = "(username like '" + queryStr+"' or username like '"+queryStr+"' )";
wrapper.addFilter(filterSql);

Page<SysUserEntity> page = this.selectPage(

new Query<SysUserEntity>(params).getPage(),
wrapper
);

工具类:

public static String toFuzzyQueryStr(String str){
char[] chars = str.toCharArray();
StringBuilder sb = new StringBuilder();
if(chars.length > 0){
sb.append("%");
}

for(int i=0;i<chars.length;i++){
sb.append(chars[i]).append("%");
}
return sb.toString();
}

打印结果如下:

Mybatis plus中一个框多条件查询 SQL拼接