三级树菜单拼接
public List<CategoryEntity> listWithTree() {
List<CategoryEntity> entities = baseMapper.selectList(null);
List<CategoryEntity> entitieList = entities.stream()
.filter(categoryEntity -> categoryEntity.getParentCid() == 0)
.map(menu -> {
menu.setChildren(getChildrens(menu, entities));
return menu;
})
.sorted((i, j) -> (i.getSort() == null ? 0 : i.getSort()) - (j.getSort() == null ? 0 : j.getSort()))
.collect(Collectors.toList());
return entitieList;
}
private List<CategoryEntity> getChildrens(CategoryEntity root, List<CategoryEntity> all) {
List<CategoryEntity> collect = all.stream().filter(categoryEntity -> categoryEntity.getParentCid() == root.getCatId())
.map(childrens -> {
childrens.setChildren(getChildrens(childrens, all));
return childrens;
})
.sorted((i, j) -> (i.getSort() == null ? 0 : i.getSort()) - (j.getSort() == null ? 0 : j.getSort()))
.collect(Collectors.toList());
return collect;
}