Collections 进行排序
List<Map<String, Object>> mapList = baseMapper.selectMaxScore(userId);
Collections.sort(mapList,new Comparator<Map<String,Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
Double s = Double.parseDouble(o1.get("score").toString());//由于从map里面取出来的值为Object类型,无法直接转换为Integer类型,需要转换为double
Double d = Double.parseDouble(o2.get("score").toString());
Double D1 = new Double(s); //由于double类型无法直接转换为Integer类型,需要用封装类先封装double
Double D2 = new Double(d);
Integer s1 = D1.intValue(); //使用Double的intValue方法转换为Integer类型
Integer s2 = D2.intValue(); //使用Entry类中的值来比较大小
return s2.compareTo(s1); //s1在前面是升序,s1在后面是降序// //使用Entry类中的键来比较大小
// return o2.getKey().compareTo(o1.getKey());
}});
Double dx = 0D;
if(!mapList.isEmpty()){
dx = (Double) mapList.get(0).get("score");
}