实现 权限树 list2Tree

      List<Resource> tree = new ArrayList<>();
        for (Resource child : list) {
            boolean mark = false;
            for (Resource father : list) {
                if (StringKit.isNotBlank(child.getPid()) && child.getPid().equals(father.getId())) {
                    mark = true;
                    if (father.getChildren() == null) {
                        father.setChildren(new ArrayList<>());
                    }
                    father.getChildren().add(child);
                    break;
                }
            }
            if (!mark) {
                tree.add(child);
            }
        }
        return tree;

 

posted @ 2018-10-25 14:34  一叶一世界abandon  阅读(426)  评论(0编辑  收藏  举报