public List<CategoryEntity> listWithTree() {
List<CategoryEntity> entities = baseMapper.selectList(null);
List<CategoryEntity> level1 = entities.stream().filter(categoryEntity ->
categoryEntity.getParentCid() == 0
).map(menu->{
menu.setChildren(getChildrens(menu,entities));
return menu;
}).sorted(Comparator.comparing(CategoryEntity::getSort)).collect(Collectors.toList());
return level1;
}
private List<CategoryEntity> getChildrens(CategoryEntity root,List<CategoryEntity> all){
List<CategoryEntity> collect = all.stream().filter(categoryEntity ->
categoryEntity.getParentCid().equals(root.getCatId())
).map(categoryEntity -> {
categoryEntity.setChildren(getChildrens(categoryEntity, all));
return categoryEntity;
}).sorted(Comparator.comparing(CategoryEntity::getSort)).collect(Collectors.toList());
return collect;
}