java后台树形菜单查询


    private List getMenuList(String doc_id) {
        List rootMenu = menuMapper.getList("root", doc_id);
        //一级目录
        List rootMenuList = new ArrayList<>();
        for (int i = 0; i < rootMenu.size(); i++) {
            MenuTree menuTree = new MenuTree();
            GuideMenuDO menuDO = rootMenu.get(i);
            menuTree.setId(menuDO.getId());
            menuTree.setName(menuDO.getLabel());
            menuTree.setMemo(menuDO.getMemo());
            //设置子目录
            menuTree.setChildren(getChildren(menuTree, doc_id));
            rootMenuList.add(menuTree);
        }
        return rootMenuList;
    }

    private List getChildren(MenuTree menuTree, String doc_id) {
        //数据库查询出来的子目录
        List menuDOList = menuMapper.getList(menuTree.getId(), doc_id);
        //前端展示的子目录
        List rootMenuList = new ArrayList<>();
        for (int i = 0; i < menuDOList.size(); i++) {
            MenuTree child = new MenuTree();
            GuideMenuDO menuDO = menuDOList.get(i);
            child.setName(menuDO.getLabel());
            child.setMemo(menuDO.getMemo());
            child.setId(menuDO.getId());
            //设置子目录
            child.setChildren(getChildren(child, doc_id));
            rootMenuList.add(child);
        }
        return rootMenuList;
    }

 

你可能感兴趣的:(java基础)