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


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

    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();
    }

    打印结果如下:

  • 相关阅读:
    51Nod1119
    stoi
    坑爹大质数
    USACO07OPEN Cheapest Palindrome
    USACO08NOV Mixed Up Cows
    USACO12FEB Nearby Cows
    SCOI2009 粉刷匠
    USACO16OPEN 248
    POI2014 PTA-Little Bird
    USACO17FEB Why Did the Cow Cross the Road I G
  • 原文地址:https://www.cnblogs.com/sanhao/p/9756061.html
Copyright © 2020-2023  润新知