JDK8 Lambda表达式——groupingby

需求:

根据结果,先对商品名分组(商品id),再根据开始时间分组

原始数据


###解决方法
groupingBy先将第一个对象(对象中有get和set方法)作为mapKey,第二个作为value

1
2
3
4
	List<PlanInfo> list = new ArrayList<>();
list = orderNInfoService.getPlanInfo(pd); //这里我在mybatis用resultmap将结果集用PlanInfo实体类来接受返回,但这个查询是查询List,所以就是List<PlanInfo>来接受
Map<String, Map<String, List<PlanInfo>>> map = list.stream()
.collect(Collectors.groupingBy(PlanInfo::getProduct_name,Collectors.groupingBy(PlanInfo::getOrder_start_time)));

结果:

具体的例子:https://blog.csdn.net/zxc514257857/article/details/72809312