首页 > 其他分享 >以树状的形式封装有孩子的节点

以树状的形式封装有孩子的节点

时间:2022-08-31 11:12:06浏览次数:64  
标签:return 树状 List categoryEntity menu2 menu1 封装 节点 getSort

@Override
    public List<CategoryEntity> listAsTree() {
        List<CategoryEntity> entities = baseMapper.selectList(null);
        List<CategoryEntity> level1Menus = entities.stream().filter(categoryEntity ->
                categoryEntity.getParentCid() == 0
        ).map((menu)->{menu.setChildren(getChildren(menu,entities));//收集之前处理再返回
            return menu;
        }).sorted((menu1,menu2)->{
            return (menu1.getSort()==null?0:menu1.getSort())-(menu2.getSort()==null?0:menu2.getSort());//排序
        }).collect(Collectors.toList());
        return level1Menus;
    }

    public List<CategoryEntity> getChildren(CategoryEntity root,List<CategoryEntity> all){
        List<CategoryEntity> children = all.stream().filter((categoryEntity) -> {
            return categoryEntity.getParentCid() == root.getCatId();
        }).map(categoryEntity -> {
            categoryEntity.setChildren(getChildren(categoryEntity,all));
            return categoryEntity;
        }).sorted((menu1,menu2)->{
            return (menu1.getSort()==null?0:menu1.getSort())-(menu2.getSort()==null?0:menu2.getSort());//排序
        }).collect(Collectors.toList());
        return children;
    }

 

标签:return,树状,List,categoryEntity,menu2,menu1,封装,节点,getSort
From: https://www.cnblogs.com/upupup-999/p/16642304.html

相关文章

  • Day25封装
    封装(数据的隐藏)通常,应禁止直接访问一个对象中数据的实际表示,而应通过操作接口来访问,这称为信息隐藏。(该露的露,该藏的藏)程序设计要追求“高内聚,低耦合”。高内聚就是类的......
  • 嵌套类匿名类与封装类
    嵌套类在C#中可以将一个类定义在另一个类的内部;外面的类叫“外部类”,内部的类叫“嵌套类”;嵌套类和普通类相似,只是声明的位置比较特殊。classPerson{//外部类......
  • 基于KubeEdge的边缘节点分组管理设计与实现
    摘要:KubeEdge1.11版本提供了“边缘节点分组管理”新特性,抽象出了跨地域的应用部署模型。本文分享自华为云社区《基于KubeEdge的边缘节点分组管理设计与实现》,作者:云容器......
  • 大家都能看得懂的源码 - 那些关于DOM的常见Hook封装(二)
    本文是深入浅出ahooks源码系列文章的第十五篇,该系列已整理成文档-地址。觉得还不错,给个star支持一下哈,Thanks。本篇接着针对关于DOM的各个Hook封装进行解读。use......
  • vue3 - 封装图表组件
      把相同或者类似的图表进行封装父组件使用:<Report:info="main4":xdata="RXData4":sdata="RSData4":title="title4"......
  • 树状数组
    241.楼兰图腾 分别统计i位置左边比a[i]小的数的个数m、右边比a[i]小的数的个数n,运用乘法原理:1.第一步从左边m个数中任选一个,有m种选法2.第二步从右边n个数中任选一个,......
  • PXC集群脑裂导致节点是无法加入无主的集群
    一套2节点的MySQLPXC集群,第1节点作为主用节点长时间的dml操作,导致大量的事务阻塞,出现异常,此时查看第2节点显示是primary状态,但无事务阻塞情况。此时第1节点无法正常提供......
  • 链表节点删除
      代码:1importjava.util.*;23publicclassMain{4publicstaticvoidmain(String[]args){5Scannerscan=newScanner(System.in);......
  • 类与封装
    packagemainimport"fmt"//如果类名首字母大写,表示其他包也能够访问typeHerostruct{//如果说类的属性首字母大写,表示该属性是对外能够访问的,否则的话只能......
  • APICloud AVM框架 封装车牌号输入键盘组件
    AVM(Application-View-Model)前端组件化开发模式基于标准WebComponents组件化思想,提供包含虚拟DOM和Runtime的编程框架avm.js以及多端统一编译工具,完全兼容WebComponents标......