List
获取到的结果是按照月分类获得的集合
先转换为List
//封装获取月份数据
public List<Map> getMonthData(List<Map> fileMaps){
List<Map> listMap = new ArrayList<>();
Map<String, List<Map>> maps = fileMaps.stream().collect(Collectors.groupingBy(
(Map m) -> (String)m.get("time"))
);
for(Map.Entry<String, List<Map>> entry:maps.entrySet()){
Map map = new HashMap();
map.put("time",entry.getKey());
map.put("data",entry.getValue());
listMap.add(map);
}
//自定义排序key值
List<Map> collect = listMap.stream().sorted(Comparator.comparing(SysFileMapServiceImpl::comparingByCreateTime))
.collect(Collectors.toList());
return collect;
}
此时得到的数据是倒序的,解决方法:
1.自定义排序方法
//通过key值对时间进行排序
private static String comparingByCreateTime(Map map){
return (String) map.get("time");
}
2.对数据数据进行倒序查询,这里不做演示。
3: 获取某一属性
List volumes= list.stream().map((Map m) -> (String)m.get(“classifyNo”)).collect(Collectors.toList());
4:分组
Map<String, List