List排序思路:通过排序的sort方法实现内部类
通过内部类取出数据进行数据格式转换及多个字段比较来确认返回的int值,从而达到多个字段排序
优点:多个字段可以根据需求进行叠加判断,更重要的是多个字段类型需要转换更可以使用代码实现。
resInvoiceLists.sort(new Comparator<ResInvoice>() {
@Override
public int compare(ResInvoice o1, ResInvoice o2) {
int lenga = o1.getSubmitTime().replaceAll(" +","").length();
SimpleDateFormat sdfs = new SimpleDateFormat("yyyy.MM.dd HH:mm");
if(lenga>16){
sdfs = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
}
Date dateb = new Date();
Date datea = new Date();
int coma = 0;
try {
dateb = sdfs.parse(o2.getSubmitTime());
datea = sdfs.parse(o1.getSubmitTime());
coma = dateb.compareTo(datea);
} catch (ParseException e) {
e.printStackTrace();
logger.info(e.getMessage());
}
if(coma == 0){
BigDecimal bigDecimalb = new BigDecimal(o2.getTotalAmount());
BigDecimal bigDecimala = new BigDecimal(o1.getTotalAmount());
coma = bigDecimalb.compareTo(bigDecimala);
}
return coma;
}
});