pojo: | |
public class CategoryTreeVO { | |
private Integer id; | |
private String name; | |
private Integer type; | |
private Integer fatherId; | |
private List<CategoryTreeVO> nodeCategoryList; | |
} | |
public List<CategoryTreeVO> treeList() { | |
List<CategoryTreeVO> treeList = categoryMapperCustom.treeList(); | |
方式2 | |
List<CategoryTreeVO> categoryTreeVOS = buildTree100(treeList, 0); | |
return categoryTreeVOS; | |
} | |
public List<CategoryTreeVO> buildTree100(List<CategoryTreeVO> list, Integer pid) { | |
List<CategoryTreeVO> trees = new ArrayList<CategoryTreeVO>(); | |
for (CategoryTreeVO categoryTree : list | |
) { | |
if (categoryTree.getFatherId().equals(pid)) { | |
List<CategoryTreeVO> nodeList = buildTree100(list, categoryTree.getId()); | |
categoryTree.setNodeCategoryList(nodeList); | |
trees.add(categoryTree); | |
} | |
} | |
return trees; | |
} |
如何快速、且易懂编写Java递归生成树形菜单结构
Java
378
0
0
2022-04-27
登录后可点赞和收藏
登录后可点赞和收藏