集合递归demo

    private List<Dept> getChildList(List<Dept> list ,Integer parentId){
        List<Dept> resList = new ArrayList();
        for(Dept dept : list){
            if(dept.getParentId() != null && dept.getParentId().intValue()== parentId.intValue()){
                List<Dept> childList = getChildList(list,dept.getId());
                dept.setChildren(childList);
                resList.add(dept);
            }
        }
        return resList;
    }

 

posted @ 2022-05-30 16:05  Sんí丶頭  阅读(23)  评论(0编辑  收藏  举报