List<MacTicket> list = new ArrayList();
Category ctg= new Category();
ctg.setType(1);//0商品,1销售规格
ctg.setSort(2);
ctg.setInheritFlag(0);//0继承属性1非继承属性
ctg.setValueSort(1)
Category ctg1= new Category();
ctg1.setType(0);//0商品,1销售规格
ctg1.setSort(1);
ctg1.setInheritFlag(1);//0继承属性1非继承属性
ctg1.setValueSort(2)
list.add(ctg);
list.add(ctg1);
lista.stream().sorted(Comparator.comparing(Category::getSort()).thenComparing(Category::getValueSort())).collect(Collectors.groupingBy(fetchGroupInheritKey(mtg)),Collectors.groupingBy(fetchGroupTypeKey(mtg)));
private String fetchGroupInheritKey(Category ctg){
if(inheritFlag==0){
return "inheritList";
}else if(inheritFlag==1){
return "ownList";
}else{
return "";
}
}
使用Comparator实现多字段排序和多级分组,前面的sort排序会影响后面的groupBy分组后的list中的排序
mcvo中有有多个property List ,按商品属性和销售属性区分将多个小list聚合为一个list
mc V o list.stream(). flat Map(mc vo→mcvo.getPropertyList(). stream ())