谷粒后端

1.    45集  三级分类

接口product/category/list/tree

@Override

public ListlistWhithTree() {

//1.查出所有分类

    List entities =baseMapper.selectList(null);

    //2.组装成父子树形结构

    //2.1找到所有一级分类

    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;

}

2. 阿里云oss 上传

你可能感兴趣的:(谷粒后端)