List<Map> zdpmjfxt = gbmdMapper.ZDPMJFXT(params);
//将积分明细信息排序好
for (int i = 0; i < zdpmjfxt.size(); i++) {
String jfmx = (String)zdpmjfxt.get(i).get("JFMX");
Map<String,Integer> map = (Map)JSONObject.parseObject(jfmx);
List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return (Integer.parseInt(o1.getKey())- Integer.parseInt(o2.getKey()));
}
});
zdpmjfxt.get(i).put("JFMX",list);
}
//将积分明细信息的规则从大到小排序
zdpmjfxt.sort(new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
List list1=(List)o1.get("JFMX");
List list2=(List)o2.get("JFMX");
for (int i = 0; i < list1.size(); i++) {
String s1 = list1.get(i).toString();
String[] split1 = s1.split("=");
String s2 = list2.get(i).toString();
String[] split2 = s2.split("=");
if(Integer.parseInt(split1[0])>Integer.parseInt(split2[0])){
return 1;
}else if(Integer.parseInt(split1[0])==Integer.parseInt(split2[0])){
if(Integer.parseInt(split1[1])>Integer.parseInt(split2[1])){
return -1;
}else if(Integer.parseInt(split1[1])<Integer.parseInt(split2[1])){
return 1;
}
}else{
return -1;
}
}
return 1;
}
});
自定义的List集合的排序
于 2022-04-02 17:25:14 首次发布