需求: 统计XX学校学生总数,
  第一级 学校,学生总数
  第二级 年级,学生数量
  第三级 班级,学生数量
  1. 主程序
 /**
     * 获取所有子节点
     *
     * @param menuList list
     * @param parentId 第一个节点的pid
     * @return 、
     */
    public static List<School> treeMenuCountsList(List<School> menuList, long parentId) {
        List<School> childMenu = new ArrayList<>();
        for (School object : menuList) {
            School school = new School();
            BeanUtils.copyProperties(object,school);
            System.out.println("school = " + school);
            if (object.getPid() == parentId){
                List<School> tree = treeMenuCountsList(menuList, object.getId());
                school.setChildren(tree);
                if (school.getChildren().size() > 0) {
                    school.setNum(school.getChildren().stream().mapToInt(School::getNum).sum());
                }
                childMenu.add(school);
            }
        }
        return childMenu;
    }

代码

Last modification:March 23rd, 2020 at 11:26 pm
如果觉得我的文章对你有用,请随意赞赏