zoukankan      html  css  js  c++  java
  • 递归查询树形菜单

    菜单表设计,一级菜单parentId都是0,二级菜单直接是插入对应得父级id即可

    public List<TResource> queryResource() {
        //查询所有得一级菜单
        Example example = new Example(TResource.class);
        Example.Criteria resourceCriteria = example.createCriteria();
        resourceCriteria.andEqualTo("parentId", 0L);
        example.orderBy("resOrder").asc();
        List<TResource> parentList =  resourceMapper.selectByExample(example);
        for(TResource tResource : parentList){
            tResource.setChildren(childList(tResource.getId()));
        }
        return parentList;
    }
    
    /**
     * 查询子菜单
     * @param parentId
     * @return
     */
    public List<TResource> childList(Long parentId){
        Example example = new Example(TResource.class);
        Example.Criteria resourceCriteria = example.createCriteria();
        resourceCriteria.andEqualTo("parentId", parentId);
        example.orderBy("resOrder").asc();
        List<TResource> childList = resourceMapper.selectByExample(example);
      
    for(TResource tResource : childList){
         //递归查询子菜单下面是否还存在子菜单 tResource.setChildren(childList(tResource.getId())); }
    return childList; }

    这里我用得是tk-mybatis,和mybatis-plus是差不多得功能,都是对mybaits得进一步封装,不需要我们去手动得写单表得sql语句。

  • 相关阅读:
    函数終探------匿名函数
    再探函数2---函数的嵌套与装饰器
    无需触摸芯片的触摸电路
    单芯片移动电源方案——1A同步升压5V--TP4351B
    HTML列表元素
    HTML表格元素
    HTML基本元素
    创建HTML5文档
    HTML5环境安装
    windows本地搭建https环境,tomcat使用https协议
  • 原文地址:https://www.cnblogs.com/wei-cy/p/13452942.html
Copyright © 2011-2022 走看看