直接上代码
注意:
if (queryUserDto.getFieldName().equals("balance")) {//用户账户余额
if (queryUserDto.getSoft().equals("asc")) { //升序
Collections.sort(vipUserMoneyVos, new Comparator<VipUserMoneyVo>() {
@Override
public int compare(VipUserMoneyVo o1, VipUserMoneyVo o2) {
if(o1.getBalance().compareTo(o2.getBalance()) < 0 ){
return -1;
}else if(o1.getBalance().compareTo(o2.getBalance()) == 0){
return 0;
}else{
return 1;
}
}
});
} else if (queryUserDto.getSoft().equals("desc")) { //降序
Collections.sort(vipUserMoneyVos, new Comparator<VipUserMoneyVo>() {
@Override
public int compare(VipUserMoneyVo o1, VipUserMoneyVo o2) {
if (o2.getBalance().compareTo(o1.getBalance()) < 0) {
return -1;
} else if (o2.getBalance().compareTo(o1.getBalance()) == 0) {
return 0;
} else {
return 1;
}
}
});
}
}