我正试图编写一个代码来按降序显示评分,但我希望例如:
我有1star到5star的评分,如果1star评分是2,3star评分是4,5star评分是1,2,4star评分是0。
现在我想按降序显示5star count、4star count、3star count、2star count和1star count。
List responseList = new ArrayList();
String lables = "54321";
String present = "";
List<Map<String, Object>> dataList = new ArrayList<Map<String,Object>>();
String sql = "select distinct count(name) name, technical from data where name =? group by Technical order by technical desc";
Map dataMap = null;
try {
dataList= jdbcTemplate.queryForList(sql,name);
for (Map<String, Object> row : dataList) {
dataMap= new HashMap();
String technicals = null;
technicals = row.get("technical")+ " Star";
present += row.get("technical");
dataMap.put("count", row.get("name"));
dataMap.put("technical", technicals);
responseList.add(dataMap);
HashSet<Character> u = unique(present,lables);
for (Character h : u) {
System.out.println(h);
dataMap= new HashMap();
dataMap.put("count", 0);
dataMap.put("technical", h + " Star");
responseList.add(dataMap);
}
}
}
1条答案
按热度按时间oxalkeyp1#
要按等级排序,请改为使用pojo
Map
,这将很容易定制排序。您的pojo应该实现可比较的接口,并且应该提供hashcode
以及equals
方法technical
现场。下面是示例代码。以及分类TreeSet
反而会更好ArrayList
.例子:
输出: