树状图
public static List<MenuTreeVo> convertToTreeVo(List<Menu> list) {
List<MenuTreeVo> treeVoList = new ArrayList<>();
Map<Integer, MenuTreeVo> treeMap = list.stream().collect(Collectors.toMap(Menu::getId, menu -> treeMapper.menuToMenuTreeVo(menu)));
treeMap.entrySet().forEach(entry -> {
MenuTreeVo treeVo = entry.getValue();
if (treeVo.getParentId() == 0) {
treeVoList.add(treeVo);
} else {
treeMap.get(treeVo.getParentId()).getChildren().add(treeVo);
}
});
return treeVoList;
}