Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-tool
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tool
amos-tool
Commits
2f7557a9
Commit
2f7557a9
authored
Dec 08, 2023
by
chenzai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit 修改组件库一级到二级由for循环改为递归
parent
2af8967f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
13 deletions
+37
-13
ToolLibraryService.java
...eejoin/amos/api/tool/face/service/ToolLibraryService.java
+37
-13
No files found.
src/main/java/com/yeejoin/amos/api/tool/face/service/ToolLibraryService.java
View file @
2f7557a9
package
com
.
yeejoin
.
amos
.
api
.
tool
.
face
.
service
;
import
com.yeejoin.amos.api.tool.face.model.TemplateCategoryTreeModel
;
import
com.yeejoin.amos.api.tool.face.model.ToolLibraryModel
;
import
com.yeejoin.amos.api.tool.face.model.ToolLibraryTreeModel
;
import
com.yeejoin.amos.api.tool.face.orm.dao.ToolLibraryMapper
;
...
...
@@ -47,24 +46,46 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
model
.
setParentId
(
Long
.
valueOf
(
map
.
get
(
"parent"
).
toString
()));
displayLists
.
add
(
model
);
}
return
getChildren
(
displayLists
);
}
public
List
<
ToolLibraryTreeModel
>
getChildren
(
List
<
ToolLibraryTreeModel
>
nodes
)
{
//新建一个用于接收数据的list
List
<
ToolLibraryTreeModel
>
resultList
=
new
ArrayList
<>();
for
(
ToolLibraryTreeModel
model1
:
nodes
)
{
for
(
ToolLibraryTreeModel
model2
:
nodes
)
{
if
(
model2
.
getParentId
().
equals
(
model1
.
getId
())){
resultList
.
add
(
model2
);
}
for
(
ToolLibraryTreeModel
result
:
displayLists
)
{
if
(
result
.
getParentId
()
==
0
)
{
//调用方法给子类添加数据
resultList
.
add
(
getMenuTree
(
result
,
displayLists
));
}
model1
.
setChildren
(
resultList
);
resultList
=
new
ArrayList
<>();
}
nodes
.
removeIf
(
model
->
model
.
getChildren
()
==
null
||
model
.
getChildren
().
size
()
==
0
)
;
return
nodes
;
return
resultList
;
// return getChildren(displayLists)
;
}
private
ToolLibraryTreeModel
getMenuTree
(
ToolLibraryTreeModel
result
,
List
<
ToolLibraryTreeModel
>
list
)
{
for
(
ToolLibraryTreeModel
treeModel
:
list
)
{
//如果父类主键等于传过来实体类的ID
if
(
treeModel
.
getParentId
().
equals
(
result
.
getId
()))
{
if
(
result
.
getChildren
()
==
null
)
{
result
.
setChildren
(
new
ArrayList
<>());
}
// 递归调用
result
.
getChildren
().
add
(
getMenuTree
(
treeModel
,
list
));
}
}
return
result
;
// public List<ToolLibraryTreeModel> getChildren(List<ToolLibraryTreeModel> nodes) {
// List<ToolLibraryTreeModel> resultList = new ArrayList<>();
// for (ToolLibraryTreeModel model1 : nodes) {
// for (ToolLibraryTreeModel model2 : nodes) {
// if (model2.getParentId().equals(model1.getId())){
// resultList.add(model2);
// }
// }
// model1.setChildren(resultList);
// resultList=new ArrayList<>();
// }
// nodes.removeIf(model -> model.getChildren() == null || model.getChildren().size() == 0);
// return nodes;
// }
// /**
// * 获得模板分类子节点(递归)
...
...
@@ -84,4 +105,6 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
// }
// return treeModels;
// }
}
}
\ No newline at end of file
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