天天看點

mybaitisplus 中 自定義排序 order by filed 的寫法

參考:

我:

// 自定義排序
List<String> barCodeList = this.getBarCodeListByImageSearchKey();
entityWrapper.in("bar_code",barCodeList);
StringBuilder builder = new StringBuilder();
int length = barCodeList.size();
for(int i=0; i<length; i++){
      if(i==0){
          builder.append(barCodeList.get(i));
      }else{
         builder.append(",")
                 .append(barCodeList.get(i));
      }
}
// 拼接成這樣:order by field(bar_code,001,002,003,004)
entityWrapper.orderBy("FIELD(bar_code,"+ builder.toString() +")");