1.? ? 45集? 三級(jí)分類
接口product/category/list/tree
@Override
public ListlistWhithTree() {
//1.查出所有分類
? ? List entities =baseMapper.selectList(null);
? ? //2.組裝成父子樹形結(jié)構(gòu)
? ? //2.1找到所有一級(jí)分類
? ? List level1Menus = entities.stream().filter(categoryEntity ->
categoryEntity.getParentCid() ==0).map((menu)->{
menu.setChildren(getChildrens(menu,entities));
? ? ? ? ? ? return menu;
? ? }).sorted((menu1,menu2)->{
return (menu1.getSort() ==null?0:menu1.getSort()) -(menu2.getSort()==null?0:menu2.getSort());
? ? }).collect(Collectors.toList());
? ? return level1Menus;
}
//遞歸查找所有菜單的子菜單
private ListgetChildrens(CategoryEntity root,List all){
List children = all.stream().filter(categoryEntity -> {
return categoryEntity.getParentCid() ==root.getCatId();
? ? }).map(categoryEntity -> {
//找到子菜單
? ? ? ? categoryEntity.setChildren(getChildrens(categoryEntity,all));
? ? ? ? return categoryEntity;
? ? }).sorted((menu1,menu2)->{
//菜單的排序
? ? ? ? return (menu1.getSort() ==null?0:menu1.getSort()) -(menu2.getSort()==null?0:menu2.getSort());
? ? }).collect(Collectors.toList());
? ? return children;
}