将List集合构建为多级菜单

private List<MenuVO> getNode(List<MenuVO> list, String parentId) {
        List<MenuVO> nodes = list.stream().filter(w -> w.getParentId().equals(parentId)).collect(Collectors.toList());
        for (MenuVO item : nodes) {
            item.setItemList(GetChildrens(list, item));
        }
        return nodes;
    }

    private List<MenuVO> GetChildrens(List<MenuVO> list, MenuVO node) {
        List<MenuVO> childrens = list.stream().filter(w -> w.getParentId().equals(node.getId())).collect(Collectors.toList());
        for (MenuVO item : childrens) {
            item.setItemList(GetChildrens(list, item));
        }
        return childrens;
    }

  

posted @ 2019-10-30 13:42  一千零一夜  阅读(569)  评论(0编辑  收藏  举报