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
a208fd3f
Commit
a208fd3f
authored
Jan 13, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:menu
parent
44c9f39a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
149 additions
and
0 deletions
+149
-0
menu/pom.xml
menu/pom.xml
+16
-0
menu/src/main/java/com/duanledexianxianxian/demo/Application.java
.../main/java/com/duanledexianxianxian/demo/Application.java
+87
-0
menu/src/main/java/com/duanledexianxianxian/demo/Menu.java
menu/src/main/java/com/duanledexianxianxian/demo/Menu.java
+18
-0
menu/src/main/java/com/duanledexianxianxian/demo/MenuVO.java
menu/src/main/java/com/duanledexianxianxian/demo/MenuVO.java
+21
-0
pom.xml
pom.xml
+7
-0
No files found.
menu/pom.xml
0 → 100644
View file @
a208fd3f
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
demo-parent
</artifactId>
<groupId>
com.duanledexianxianxian.demo
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
menu
</artifactId>
</project>
\ No newline at end of file
menu/src/main/java/com/duanledexianxianxian/demo/Application.java
0 → 100644
View file @
a208fd3f
package
com.duanledexianxianxian.demo
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Lists
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author duanledexianxianxian
* @date 2020/1/12 23:51
* @since 1.0.0
*/
public
class
Application
{
private
static
String
[][]
menus
=
{
{
null
,
"0001"
,
"用户管理"
,
"/urlMgr"
},
{
"0001"
,
"00010001"
,
"用户管理-添加用户"
,
"/urlMgr/add"
},
{
"0001"
,
"00010002"
,
"用户管理-修改用户"
,
"/urlMgr/edit"
},
{
"0001"
,
"00010003"
,
"用户管理-删除用户"
,
"/urlMgr/delete"
},
{
"0001"
,
"00010004"
,
"用户管理-查询用户"
,
"/urlMgr/query"
},
{
null
,
"0002"
,
"系统管理"
,
"/systemMgr"
},
{
"0002"
,
"00020001"
,
"系统管理-系统管理0001"
,
"/systemMgr/0001"
},
{
"00020001"
,
"000200010001"
,
"系统管理-系统管理0001-系统管理0001"
,
"/systemMgr/0001/0001"
},
{
"000200010001"
,
"0002000100010001"
,
"系统管理-系统管理0001-系统管理0001-系统管理0001"
,
"/systemMgr/0001/0001/0001"
},
};
public
static
void
main
(
String
[]
args
)
{
List
<
Menu
>
menuList
=
Lists
.
newArrayList
();
Arrays
.
asList
(
menus
).
forEach
(
x
->
{
Menu
menu
=
new
Menu
();
menu
.
setParentMenuCode
(
x
[
0
]);
menu
.
setMenuCode
(
x
[
1
]);
menu
.
setMenuTitle
(
x
[
2
]);
menu
.
setMenuUrl
(
x
[
3
]);
menuList
.
add
(
menu
);
});
menuList
.
forEach
(
x
->
System
.
out
.
println
(
x
.
toString
()));
MenuVO
menuVO
=
getTreeMenuVO
(
menuList
);
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
System
.
out
.
println
(
mapper
.
writeValueAsString
(
menuVO
));
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
}
private
static
MenuVO
getTreeMenuVO
(
List
<
Menu
>
menuList
)
{
if
(
CollectionUtils
.
isEmpty
(
menuList
))
{
return
null
;
}
List
<
MenuVO
>
menuVOList
=
Lists
.
newArrayList
();
menuList
.
forEach
(
x
->
{
MenuVO
menuVO
=
new
MenuVO
();
BeanUtils
.
copyProperties
(
x
,
menuVO
);
menuVOList
.
add
(
menuVO
);
});
// 转成map
Map
<
String
,
MenuVO
>
menuMap
=
menuVOList
.
stream
().
collect
(
Collectors
.
toMap
(
MenuVO:
:
getMenuCode
,
x
->
x
));
// 构建根节点
MenuVO
menuVO
=
new
MenuVO
();
menuVO
.
setParentMenuCode
(
null
);
menuVO
.
setMenuCode
(
"root"
);
menuVO
.
setMenuTitle
(
"根节点"
);
for
(
MenuVO
menu
:
menuVOList
)
{
if
(
menuMap
.
containsKey
(
menu
.
getParentMenuCode
()))
{
if
(
menuMap
.
get
(
menu
.
getParentMenuCode
()).
getChildren
()
==
null
)
{
menuMap
.
get
(
menu
.
getParentMenuCode
()).
setChildren
(
Lists
.
newArrayList
());
}
menuMap
.
get
(
menu
.
getParentMenuCode
()).
getChildren
().
add
(
menu
);
}
else
{
if
(
menuVO
.
getChildren
()
==
null
)
{
menuVO
.
setChildren
(
Lists
.
newArrayList
());
}
menuVO
.
getChildren
().
add
(
menu
);
}
}
return
menuVO
;
}
}
menu/src/main/java/com/duanledexianxianxian/demo/Menu.java
0 → 100644
View file @
a208fd3f
package
com.duanledexianxianxian.demo
;
import
lombok.Data
;
/**
* 菜单
*
* @author duanledexianxianxian
* @date 2020/1/12 23:49
* @since 1.0.0
*/
@Data
public
class
Menu
{
private
String
parentMenuCode
;
private
String
menuCode
;
private
String
menuTitle
;
private
String
menuUrl
;
}
menu/src/main/java/com/duanledexianxianxian/demo/MenuVO.java
0 → 100644
View file @
a208fd3f
package
com.duanledexianxianxian.demo
;
import
lombok.Data
;
import
java.util.List
;
/**
* 菜单
*
* @author duanledexianxianxian
* @date 2020/1/12 23:49
* @since 1.0.0
*/
@Data
public
class
MenuVO
{
private
String
parentMenuCode
;
private
String
menuCode
;
private
String
menuTitle
;
private
String
menuUrl
;
private
List
<
MenuVO
>
children
;
}
pom.xml
View file @
a208fd3f
...
...
@@ -10,6 +10,7 @@
<version>
1.0-SNAPSHOT
</version>
<modules>
<module>
kafka
</module>
<module>
menu
</module>
</modules>
<parent>
...
...
@@ -39,6 +40,12 @@
<artifactId>
json-path
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
23.0
</version>
</dependency>
</dependencies>
<properties>
...
...
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