private List<TreeNode> createTree(Integer pid, Map<Integer, List<SysPermission>> map){
return Optional.ofNullable(map.get(pid)).orElseGet(()->new ArrayList<SysPermission>()).stream().filter(x->x.getParentId() == pid).sorted((x,y)->{return x.getSortNo().compareTo(y.getSortNo());}).map(x->{
return new TreeNode(x.getRecId(), x.getParentId(), x.getPermissionName(), x.getIcon(), createTree(x.getRecId(), map));
}).collect(Collectors.toList());
} private List<TreeNode> getTree(boolean onlyModule){
EntityWrapper<SysPermission> entityWrapper = new EntityWrapper<>();
entityWrapper.where("data_status>0");
if (onlyModule){
entityWrapper.eq("permission_type", PermissionType.MODULE.getValue());
}
entityWrapper.orderBy("sort_no");
List<SysPermission> list = selectList(entityWrapper);
return createTree(0, list.stream().collect(groupingBy(SysPermission::getParentId)));
} TreeNode的定义:
public class TreeNode {
private static final long serialVersionUID = 1L; private Integer recId;
private Integer pid;
private String nodeName;
private String icon;
private List<TreeNode> children; public TreeNode(Integer recId, Integer pid, String nodeName, String icon) {
this.recId = recId;
this.pid = pid;
this.nodeName = nodeName;
this.icon = icon;
this.children = new ArrayList<TreeNode>();
} public TreeNode(Integer recId, Integer pid, String nodeName, String icon, List<TreeNode> children) {
this.recId = recId;
this.pid = pid;
this.nodeName = nodeName;
this.icon = icon;
this.children = children;
} public Integer getRecId() {
return recId;
} public void setRecId(Integer recId) {
this.recId = recId;
} public Integer getPid() {
return pid;
} public void setPid(Integer pid) {
this.pid = pid;
} public String getNodeName() {
return nodeName;
} public void setNodeName(String nodeName) {
this.nodeName = nodeName;
} public String getIcon() {
return icon;
} public void setIcon(String icon) {
this.icon = icon;
} public List<TreeNode> getChildren() {
return children;
} public void setChildren(List<TreeNode> children) {
this.children = children;
}
}

最新文章

  1. C# 实时折线图,波形图
  2. JavaScript 事件 编程练习
  3. 二:【nopcommerce系列】Nop的文件结构,引用关系。如何编译打包部署等
  4. placeholder兼容
  5. easyui+ashx 动态初始化datagrid(动态列头)
  6. POJ C程序设计进阶 编程题#1:寻找下标
  7. javascript 高效按字节截取字符串
  8. SSM框架整合基本操作
  9. HDOJ1253 胜利大逃亡 BFS
  10. javascript数组去重算法-----3
  11. sicily9162. RAZLIKA
  12. [Q]自定义保存位置及文件名
  13. cp的用法
  14. Web前端性能优化——如何有效提升静态文件的加载速度
  15. 浅谈我为什么选择用Retrofit作为我的网络请求框架
  16. 7系列FPGA的时钟资源——UG472
  17. 代码规范与复审2——个人博客作业week
  18. C++进程间通信之共享内存
  19. arm irq system
  20. [leetcode]Path Sum @ Python

热门文章

  1. 申请内存的方式(1,malloc/free;2,new/delete)
  2. java入门了解之快捷键
  3. DL一(ML基础知识)
  4. Codeforces 358D Dima and Hares:dp【只考虑相邻元素】
  5. c++能过,g++过不了
  6. long long 与 __int64
  7. Java微信开发_Exception_02_&quot;errcode&quot;:40164,&quot;errmsg&quot;:&quot;invalid ip 61.172.68.219, not in whitelist hint
  8. linux命令学习笔记(41):ps命令
  9. uoj problem 31 猪猪侠再战括号序列
  10. 图形化升级单机oracle 11.2.0.4 到 12.2.0.1