Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
springboot-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
springboot-demo
Commits
259741fc
Commit
259741fc
authored
Jan 13, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:menu
parent
a208fd3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
menu/src/main/java/com/duanledexianxianxian/demo/Application.java
.../main/java/com/duanledexianxianxian/demo/Application.java
+8
-1
No files found.
menu/src/main/java/com/duanledexianxianxian/demo/Application.java
View file @
259741fc
...
@@ -50,17 +50,23 @@ public class Application {
...
@@ -50,17 +50,23 @@ public class Application {
}
}
}
}
/**
* 平级列表转成树结构
* @param menuList
* @return
*/
private
static
MenuVO
getTreeMenuVO
(
List
<
Menu
>
menuList
)
{
private
static
MenuVO
getTreeMenuVO
(
List
<
Menu
>
menuList
)
{
if
(
CollectionUtils
.
isEmpty
(
menuList
))
{
if
(
CollectionUtils
.
isEmpty
(
menuList
))
{
return
null
;
return
null
;
}
}
List
<
MenuVO
>
menuVOList
=
Lists
.
newArrayList
();
List
<
MenuVO
>
menuVOList
=
Lists
.
newArrayList
();
// 类型转换 一层循环
menuList
.
forEach
(
x
->
{
menuList
.
forEach
(
x
->
{
MenuVO
menuVO
=
new
MenuVO
();
MenuVO
menuVO
=
new
MenuVO
();
BeanUtils
.
copyProperties
(
x
,
menuVO
);
BeanUtils
.
copyProperties
(
x
,
menuVO
);
menuVOList
.
add
(
menuVO
);
menuVOList
.
add
(
menuVO
);
});
});
// 转成map
// 转成map
二层循环 一层与二层可以合并
Map
<
String
,
MenuVO
>
menuMap
=
menuVOList
.
stream
().
collect
(
Collectors
.
toMap
(
MenuVO:
:
getMenuCode
,
x
->
x
));
Map
<
String
,
MenuVO
>
menuMap
=
menuVOList
.
stream
().
collect
(
Collectors
.
toMap
(
MenuVO:
:
getMenuCode
,
x
->
x
));
// 构建根节点
// 构建根节点
MenuVO
menuVO
=
new
MenuVO
();
MenuVO
menuVO
=
new
MenuVO
();
...
@@ -68,6 +74,7 @@ public class Application {
...
@@ -68,6 +74,7 @@ public class Application {
menuVO
.
setMenuCode
(
"root"
);
menuVO
.
setMenuCode
(
"root"
);
menuVO
.
setMenuTitle
(
"根节点"
);
menuVO
.
setMenuTitle
(
"根节点"
);
// 转换逻辑 三层循环
for
(
MenuVO
menu
:
menuVOList
)
{
for
(
MenuVO
menu
:
menuVOList
)
{
if
(
menuMap
.
containsKey
(
menu
.
getParentMenuCode
()))
{
if
(
menuMap
.
containsKey
(
menu
.
getParentMenuCode
()))
{
if
(
menuMap
.
get
(
menu
.
getParentMenuCode
()).
getChildren
()
==
null
)
{
if
(
menuMap
.
get
(
menu
.
getParentMenuCode
()).
getChildren
()
==
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment