实现权限树 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;

猜你喜欢

转载自www.cnblogs.com/yang21/p/9849675.html
今日推荐