伟大文献:java 实现二级动态菜单功能_java二级菜单的实现-CSDN博客
鄙人微调
1.代码
public Result getManualModeMenu(Integer modelId) {
//组装数据
List<Map> objects = new ArrayList<>();
//查询父级
QueryWrapper<ManualModeMenu> getAll = new QueryWrapper<>();
getAll.lambda().eq(ManualModeMenu::getModelId,modelId).eq(ManualModeMenu::getPid,0);
List<ManualModeMenu> manualModeMenus = manualModeIMenuMapper.selectList(getAll);
for (ManualModeMenu menu:manualModeMenus){
Map fatherMap = new HashMap();
fatherMap.put("id",menu.getId());
fatherMap.put("name",menu.getMenuName());
List children = new ArrayList<>();
QueryWrapper<ManualModeMenu> getChild = new QueryWrapper<>();
getChild.lambda().eq(ManualModeMenu::getModelId,modelId).eq(ManualModeMenu::getPid,menu.getId());
List<ManualModeMenu> manu = manualModeIMenuMapper.selectList(getChild);
if (manu != null && manu.size() > 0){
for (ManualModeMenu mu : manu){
Map smMap = new HashMap();
smMap.put("id",mu.getId());
smMap.put("name",mu.getMenuName());
smMap.put("pid",mu.getPid());
children.add(smMap);
}
fatherMap.put("children",children);
}else {
fatherMap.put("children",null);
}
objects.add(fatherMap);
}
System.out.println("XXX");
return Result.success(null);
}
2.数据库