List<Map<String, Object>> list = jdbc.queryForList(sql.toString(), communityId,communityId);
Collections.sort(list, new MapComparatorAsc());
//升序排序
static class MapComparatorAsc implements Comparator<Map<String, Object>> {
@Override
public int compare(Map<String, Object> m1, Map<String, Object> m2) {
Integer v1 = Integer.valueOf(m1.get("type").toString());
Integer v2 = Integer.valueOf(m2.get("type").toString());
if(v1 != null){
return v1.compareTo(v2);
}
return 0;
}
}
//降序排序
static class MapComparatorDesc implements Comparator<Map<String, Object>> {
@Override
public int compare(Map<String, Object> m1, Map<String, Object> m2) {
Integer v1 = Integer.valueOf(m1.get("count").toString());
Integer v2 = Integer.valueOf(m2.get("count").toString());
if (v2 != null) {
return v2.compareTo(v1);
}
return 0;
}
}
}