Java多级菜单递归拼装Demo

JEECG的改造 Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@Override
public List<TSFunction> getFunctionByRoleId(String roleId) {
List<TSFunction> functionList = new ArrayList<>();

// 查询全部菜单
List<TSFunction> functionList0 = tSFunctionMapper.selectAll();
// 角色权限相关菜单
List<TSFunction> roleFunctionList = tSRoleMapper.getFunctionByRoleId(roleId);
for (TSFunction function0 : functionList0) {
function0.setChildren(makeFunctionList(functionList0, function0.getId(), roleFunctionList));
// 只添加一级菜单(下级菜单已拼装好在里面)
if (StringUtil.isEmpty(function0.getParentfunctionid())) {
functionList.add(function0);
}
}

return functionList;
}

public List<TSFunction> makeFunctionList(List<TSFunction> srcFunctionList, String functionId, List<TSFunction> roleFunctionList) {
List<TSFunction> functionList = new ArrayList<>();
for (TSFunction function : srcFunctionList) {
String id = function.getId();
String parentfunctionid = function.getParentfunctionid();
// 非一级菜单递归查询
if (StringUtil.isNotEmpty(parentfunctionid)) {
if (parentfunctionid.equals(functionId)) {
function.setChildren(makeFunctionList(srcFunctionList, id, roleFunctionList));
functionList.add(function);
}
}

// 角色权限√处理
for (TSFunction roleFunction : roleFunctionList) {
if (id.equals(roleFunction.getId())) {
function.setChecked(1);
}
}
}
return functionList;
}

部分返回结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
"id": "402889fb486e848101486e8de3d60005",
"functionlevel": 0,
"functionname": "数据权限",
"functionorder": "100",
"iconid": "8a8ab0b246dc81120146dc8180820003",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": [
{
"id": "402880f25a980e2a015a981dc8de0005",
"functionlevel": 1,
"functionname": "请假自定义表单",
"functionorder": "3",
"functionurl": "autoFormController/af/employee_leave_form/goViewPage.do",
"parentfunctionid": "402889fb486e848101486e8de3d60005",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "402880f25a9833f5015a9843218f000c",
"functionlevel": 1,
"functionname": "自定义表单查看",
"functionorder": "4",
"functionurl": "autoFormController/af/order_form/goUpdatePage.do",
"parentfunctionid": "402889fb486e848101486e8de3d60005",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "402881855ab8c48a015ab8d133050018",
"functionlevel": 1,
"functionname": "测试online表单权限",
"functionorder": "4",
"parentfunctionid": "402889fb486e848101486e8de3d60005",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": [
{
"id": "402880f25b1d5a3a015b1d772c2b0013",
"functionlevel": 1,
"functionname": "请假单编辑页面",
"functionorder": "2",
"functionurl": "cgFormBuildController/ftlForm/jform_leave/goUpdate.do",
"parentfunctionid": "402881855ab8c48a015ab8d133050018",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "402880f25b1e2ac7015b1e5cdc340010",
"functionlevel": 2,
"functionname": "online请假加载数据请求",
"functionorder": "3",
"functionurl": "cgAutoListController.do?datagrid&configId=jform_leave",
"parentfunctionid": "402881855ab8c48a015ab8d133050018",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "402880f25b23a635015b23a992f10003",
"functionlevel": 1,
"functionname": "ol订单编辑页面",
"functionorder": "4",
"functionurl": "cgFormBuildController/ftlForm/jform_order_main/goUpdate.do",
"parentfunctionid": "402881855ab8c48a015ab8d133050018",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "402881855ab8c48a015ab8d1f96f001b",
"functionlevel": 1,
"functionname": "ol请假单查看页面",
"functionorder": "1",
"functionurl": "cgFormBuildController/ftlForm/jform_leave/goDetail.do",
"parentfunctionid": "402881855ab8c48a015ab8d133050018",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
}
]
},
{
"id": "4028ef81574ae99701574aeb97bd0003",
"functionlevel": 1,
"functionname": "用户列表数据权限",
"functionorder": "2",
"functionurl": "userController.do?datagrid",
"parentfunctionid": "402889fb486e848101486e8de3d60005",
"iconid": "8a8ab0b246dc81120146dc8180460000",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
},
{
"id": "40288088481d019401481d2fcebf000d",
"functionlevel": 1,
"functionname": "minidao数据权限列表",
"functionorder": "1",
"functionurl": "jeecgListDemoController.do?minidaoDatagrid",
"parentfunctionid": "402889fb486e848101486e8de3d60005",
"iconid": "8a8ab0b246dc81120146dc8180820003",
"deskIconid": "8a8ab0b246dc81120146dc8180dd001e",
"functiontype": 1,
"checked": 0,
"children": []
}
]
}