List<PdTechnologyCommunityComment> pdTechnologyCommunityComments = pdTechnologyCommunityCommentMapper.listAllByPdTechnologyCommunityComment(var);
需要组装的数据
List<PdTechnologyCommunityComment> collect = pdTechnologyCommunityComments.stream().filter(o -> o.getParentCid() == 0)
// 给每个一级分类加子分类
.peek(o -> o.setChildrens(getChildCategoryList(o, categories)))
// 排序
.sorted(Comparator.comparingInt(CategoryEntity::getSort))
// 收集
.collect(Collectors.toList());
// 根据当前分类 找出子类, 并通过递归找出子类的子类
private List<PdTechnologyCommunityComment> getChildCategoryList(PdTechnologyCommunityComment currMenu, List<PdTechnologyCommunityComment> categories) {
return categories.stream().filter(o -> o.getParentCid().equals(currMenu.getCatId()))
.peek(o -> o.setChildrens(getChildCategoryList(o, categories)))
.sorted(Comparator.comparingInt(CategoryEntity::getSort))
.collect(Collectors.toList());
}
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/275632.html