递归获取菜单栏

Posted onfe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归获取菜单栏相关的知识,希望对你有一定的参考价值。

@Override
public BaseResponse<?> listChildSort(){
//查找所有最上级菜单
List<SysPermission> sysPermissionList = sysPermissionMapper.selectByParentId(0);
List<Children> childrenList = Lists.newArrayList();
for(SysPermission sysPermission : sysPermissionList){
//添加该菜单下及其下级菜单的递归集合
childrenList.add(listChild(sysPermission));
}
if(childrenList.size() == 0 ){
return BaseResponse.createByError("没有数据了");
}
return BaseResponse.createBySuccess(childrenList);
}
private Children listChild(SysPermission sysPermission){
//新建递归对象
Children children = new Children();
//把当前菜单Id和Name存进该对象
children.setId(sysPermission.getId()+"");
children.setName(sysPermission.getName());
//查找上级菜单为当前菜单ID的菜单
List<SysPermission> sysPermissionList = sysPermissionMapper.selectByParentId(sysPermission.getId().intValue());
List<Children> childrenList = Lists.newArrayList();
//遍历下级菜单
for(SysPermission sysPermissionChild : sysPermissionList){
//递归下级菜单,并存入下级菜单集合
childrenList.add(listChild(sysPermissionChild));
}
//将下级菜单集合存进递归对象
children.setChildren(childrenList.size() > 0 ? childrenList : null);
return children;
}

以上是关于递归获取菜单栏的主要内容,如果未能解决你的问题,请参考以下文章

简单递归写侧边菜单栏

vue+elemenUi+menu实现树形导航栏递归组件目录菜单menuforEachMathfloorrandom

vue+elemenUi+menu实现树形导航栏递归组件目录菜单menuforEachMathfloorrandom

C# winform 获取标题栏,状态栏,菜单栏的高度

获取特定任务栏按钮的上下文菜单文本

如何在图像下直接获取菜单栏? [关闭]