遇到多条件查询时,只用框架自带的方法搞不定,只能自己写方法拼接
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();
}
打印结果如下: