Java教程

java 单表树形组装

本文主要是介绍java 单表树形组装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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());
}
这篇关于java 单表树形组装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!