结构不多说,bean的封装很简单,直接上核心代码吧,自己根据需要把不要的属性自己过滤掉:

    public List<MenuBo> getMenuByUserId(Long user_id,Long company_id) {

        //获取所有的菜单
List<MenuBo> rootMenu = new ArrayList<>();
rootMenu = companyFuncInfoMapper.getMenuByUserId(user_id); List<Long> func_list = companyFuncInfoMapper.getFuncCompanyIdShipByCompanyId(company_id);
Iterator<MenuBo> it=rootMenu.iterator();
while(it.hasNext()){
MenuBo menuBoIt=it.next();
if(!func_list.contains(menuBoIt.getId())){
it.remove();
}
}
//最后的结果
List<MenuBo> menuList = new ArrayList<>(); // 先找到所有的一级菜单
for (int i = 0; i < rootMenu .size(); i++) {
// 一级菜单没有parentId
if (rootMenu .get(i).getPid()==0L) {
// 一级菜单没有parentId
menuList.add(rootMenu.get(i)); }
} // 为一级菜单设置子菜单,getChild是递归调用的
for (MenuBo menu : menuList) {
Meta meta = new Meta();
meta.setBreadName(menu.getBreadName());
meta.setBreadIcon(menu.getBreadIcon());
meta.setTitle(menu.getBreadName());
menu.setComponent(menu.getComponent());
menu.setMeta(meta);
menu.setChildren(getChild(menu.getId(), rootMenu));
}
return menuList;
}

获取子菜单的方法:

private static List<MenuBo> getChild(Long id, List<MenuBo> rootMenu) {
// 子菜单
List<MenuBo> childList = new ArrayList<>(); for (MenuBo menu : rootMenu) {
// 遍历所有节点,将父菜单id与传过来的id比较
if (menu.getPid()!=null) {
if (menu.getPid().intValue()==id.intValue()) {
Meta meta = new Meta();
meta.setBreadName(menu.getBreadName());
meta.setBreadIcon(menu.getBreadIcon());
meta.setTitle(menu.getBreadName()); menu.setMeta(meta);
menu.setComponent(menu.getComponent());
menu.setTitle(menu.getBreadName()); childList.add(menu);
}
}
}
// 把子菜单的子菜单再循环一遍
for (MenuBo children : childList) {// 没有url子菜单还有子菜单
if (StringUtils.isBlank(children.getPath())) {
// 递归 children.setChildren(getChild(children.getId(), rootMenu));
}
} // 递归退出条件
if (childList.size() == 0) {
return null;
}
return childList;
}

最终结果:

{
"code": "000000",
"msg": "SUCCESS",
"data": [{
"id": 119,
"pid": 0,
"path": "",
"name": "parkManage",
"breadName": "停车场管理",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 121,
"pid": 119,
"path": "",
"name": "parkInfo",
"breadName": "停车场基本信息",
"component": "parkManagement/parkInfo/parkInfo",
"breadIcon": "ios-cafe",
"title": "停车场基本信息",
"func_type": "0",
"children": [{
"id": 140,
"pid": 121,
"path": "",
"name": "parkInfoManage",
"breadName": "停车场信息管理",
"component": "parkManagement/parkInfo/parkInfoManage",
"breadIcon": "ios-cafe",
"title": "停车场信息管理",
"func_type": "2",
"children": null,
"meta": {
"breadName": "停车场信息管理",
"breadIcon": "ios-cafe",
"title": "停车场信息管理"
}
}, {
"id": 146,
"pid": 121,
"path": "businessUser",
"name": "businessUser",
"breadName": "商家用户管理",
"component": "parkManagement/parkInfo/businessUser",
"breadIcon": "ios-cafe",
"title": "商家用户管理",
"func_type": "2",
"children": null,
"meta": {
"breadName": "商家用户管理",
"breadIcon": "ios-cafe",
"title": "商家用户管理"
}
}],
"meta": {
"breadName": "停车场基本信息",
"breadIcon": "ios-cafe",
"title": "停车场基本信息"
}
}, {
"id": 122,
"pid": 119,
"path": "parkConfig",
"name": "parkConfig",
"breadName": "停车场配置",
"component": "parkManagement/parkConfig/parkConfig",
"breadIcon": "ios-cafe",
"title": "停车场配置",
"func_type": "0",
"children": null,
"meta": {
"breadName": "停车场配置",
"breadIcon": "ios-cafe",
"title": "停车场配置"
}
}],
"meta": {
"breadName": "停车场管理",
"breadIcon": "logo-buffer",
"title": "停车场管理"
}
}, {
"id": 123,
"pid": 0,
"path": "",
"name": "flowDetails",
"breadName": "流水明细查询",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 124,
"pid": 123,
"path": "carflowInfos",
"name": "carflowInfos",
"breadName": "离场记录",
"component": "flowDetailsQuiry/carflowInfo",
"breadIcon": "ios-cafe",
"title": "离场记录",
"func_type": "0",
"children": null,
"meta": {
"breadName": "离场记录",
"breadIcon": "ios-cafe",
"title": "离场记录"
}
}, {
"id": 126,
"pid": 123,
"path": "flowingWater",
"name": "flowingWater",
"breadName": "在场车辆",
"component": "flowDetailsQuiry/flowingWater",
"breadIcon": "ios-cafe",
"title": "在场车辆",
"func_type": "0",
"children": null,
"meta": {
"breadName": "在场车辆",
"breadIcon": "ios-cafe",
"title": "在场车辆"
}
}, {
"id": 125,
"pid": 123,
"path": "payWater",
"name": "payWater",
"breadName": "收费流水",
"component": "flowDetailsQuiry/payWater",
"breadIcon": "ios-cafe",
"title": "收费流水",
"func_type": "0",
"children": null,
"meta": {
"breadName": "收费流水",
"breadIcon": "ios-cafe",
"title": "收费流水"
}
}],
"meta": {
"breadName": "流水明细查询",
"breadIcon": "logo-buffer",
"title": "流水明细查询"
}
}, {
"id": 127,
"pid": 0,
"path": "",
"name": "reportQuery",
"breadName": "报表查询",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 128,
"pid": 127,
"path": "chargeDailyReport",
"name": "chargeDailyReport",
"breadName": "收费统计日报表",
"component": "reportQuery/chargeDailyReport",
"breadIcon": "ios-cafe",
"title": "收费统计日报表",
"func_type": "0",
"children": null,
"meta": {
"breadName": "收费统计日报表",
"breadIcon": "ios-cafe",
"title": "收费统计日报表"
}
}, {
"id": 147,
"pid": 127,
"path": "vehicleReport",
"name": "vehicleReport",
"breadName": "车辆进出场报表",
"component": "reportQuery/vehicleReport",
"breadIcon": "ios-cafe",
"title": "车辆进出场报表",
"func_type": "0",
"children": null,
"meta": {
"breadName": "车辆进出场报表",
"breadIcon": "ios-cafe",
"title": "车辆进出场报表"
}
}, {
"id": 148,
"pid": 127,
"path": "temporaryReport",
"name": "temporaryReport",
"breadName": "临停收费报表",
"component": "reportQuery/temporaryReport",
"breadIcon": "ios-cafe",
"title": "临停收费报表",
"func_type": "0",
"children": null,
"meta": {
"breadName": "临停收费报表",
"breadIcon": "ios-cafe",
"title": "临停收费报表"
}
}, {
"id": 149,
"pid": 127,
"path": "paymentReport",
"name": "paymentReport",
"breadName": "支付统计报表",
"component": "reportQuery/paymentReport",
"breadIcon": "ios-cafe",
"title": "支付统计报表",
"func_type": "0",
"children": null,
"meta": {
"breadName": "支付统计报表",
"breadIcon": "ios-cafe",
"title": "支付统计报表"
}
}],
"meta": {
"breadName": "报表查询",
"breadIcon": "logo-buffer",
"title": "报表查询"
}
}, {
"id": 129,
"pid": 0,
"path": "",
"name": "financialControl",
"breadName": "财务管理",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 130,
"pid": 129,
"path": "merchant",
"name": "merchant",
"breadName": "商家充值",
"component": "financialManage/merchant",
"breadIcon": "ios-cafe",
"title": "商家充值",
"func_type": "0",
"children": null,
"meta": {
"breadName": "商家充值",
"breadIcon": "ios-cafe",
"title": "商家充值"
}
}, {
"id": 131,
"pid": 129,
"path": "vipRecharge",
"name": "vipRecharge",
"breadName": "VIP开通/续费",
"component": "financialManage/vipRecharge",
"breadIcon": "ios-cafe",
"title": "VIP开通/续费",
"func_type": "0",
"children": null,
"meta": {
"breadName": "VIP开通/续费",
"breadIcon": "ios-cafe",
"title": "VIP开通/续费"
}
}, {
"id": 144,
"pid": 129,
"path": "rechargeRule",
"name": "rechargeRule",
"breadName": "充值规则管理",
"component": "financialManage/rechargeRule",
"breadIcon": "ios-cafe",
"title": "充值规则管理",
"func_type": "0",
"children": null,
"meta": {
"breadName": "充值规则管理",
"breadIcon": "ios-cafe",
"title": "充值规则管理"
}
}],
"meta": {
"breadName": "财务管理",
"breadIcon": "logo-buffer",
"title": "财务管理"
}
}, {
"id": 132,
"pid": 0,
"path": "",
"name": "carOwnerManagement",
"breadName": "车主管理",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 133,
"pid": 132,
"path": "carOwner",
"name": "carOwner",
"breadName": "车主信息",
"component": "carOwnerManagement/carowner",
"breadIcon": "ios-cafe",
"title": "车主信息",
"func_type": "0",
"children": null,
"meta": {
"breadName": "车主信息",
"breadIcon": "ios-cafe",
"title": "车主信息"
}
}, {
"id": 134,
"pid": 132,
"path": "vehicle",
"name": "vehicle",
"breadName": "车辆管理",
"component": "carOwnerManagement/vehicle/vehicle",
"breadIcon": "ios-cafe",
"title": "车辆管理",
"func_type": "0",
"children": null,
"meta": {
"breadName": "车辆管理",
"breadIcon": "ios-cafe",
"title": "车辆管理"
}
}, {
"id": 135,
"pid": 132,
"path": "vipType",
"name": "vipType",
"breadName": "VIP类型",
"component": "carOwnerManagement/vip/vip",
"breadIcon": "ios-cafe",
"title": "VIP类型",
"func_type": "0",
"children": null,
"meta": {
"breadName": "VIP类型",
"breadIcon": "ios-cafe",
"title": "VIP类型"
}
}],
"meta": {
"breadName": "车主管理",
"breadIcon": "logo-buffer",
"title": "车主管理"
}
}, {
"id": 44,
"pid": 0,
"path": "",
"name": "systemManagement",
"breadName": "系统管理",
"component": "homePage",
"breadIcon": "logo-buffer",
"title": null,
"func_type": "0",
"children": [{
"id": 47,
"pid": 44,
"path": "userManagement",
"name": "userManagement",
"breadName": "用户管理",
"component": "systemManagement/userManagement/user",
"breadIcon": "ios-cafe",
"title": "用户管理",
"func_type": "0",
"children": null,
"meta": {
"breadName": "用户管理",
"breadIcon": "ios-cafe",
"title": "用户管理"
}
}, {
"id": 48,
"pid": 44,
"path": "roleManagement",
"name": "roleManagement",
"breadName": "角色管理",
"component": "systemManagement/roleManagement/role",
"breadIcon": "ios-cafe",
"title": "角色管理",
"func_type": "0",
"children": null,
"meta": {
"breadName": "角色管理",
"breadIcon": "ios-cafe",
"title": "角色管理"
}
}, {
"id": 49,
"pid": 44,
"path": "functionalManagement",
"name": "functionalManagement",
"breadName": "功能管理",
"component": "systemManagement/functionalManagement/functional",
"breadIcon": "ios-cafe",
"title": "功能管理",
"func_type": "0",
"children": null,
"meta": {
"breadName": "功能管理",
"breadIcon": "ios-cafe",
"title": "功能管理"
}
}],
"meta": {
"breadName": "系统管理",
"breadIcon": "logo-buffer",
"title": "系统管理"
}
}, {
"id": 142,
"pid": 0,
"path": "/homePage",
"name": "",
"breadName": "首页",
"component": "homePage",
"breadIcon": "ios-home",
"title": null,
"func_type": "0",
"children": [{
"id": 143,
"pid": 142,
"path": "",
"name": "homeMain",
"breadName": "控制台",
"component": "homeMain/homeMain",
"breadIcon": "md-settings",
"title": "控制台",
"func_type": "0",
"children": null,
"meta": {
"breadName": "控制台",
"breadIcon": "md-settings",
"title": "控制台"
}
}],
"meta": {
"breadName": "首页",
"breadIcon": "ios-home",
"title": "首页"
}
}]
}

大家看json结构自己写一下实体类就行了。

递归处理vue菜单数据的更多相关文章

  1. C# 递归读取XML菜单数据

    在博客园注册了有4年了,很遗憾至今仍未发表过博客,趁周末有空发表第一篇博客.小生不才,在此献丑了! 最近在研究一些关于C#的一些技术,纵观之前的开发项目的经验,做系统时显示系统菜单的功能总是喜欢把数据 ...

  2. PHP递归获得树形菜单和遍历文件夹下的所有文件以及子文件夹

    PHP递归获得树形菜单和遍历文件夹下的所有文件以及子文件夹 一.使用递归获取树形菜单 数据表category(id,name,parent_id) <?php class category{ / ...

  3. 基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据

    最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框架保持一致,而在Web上,我主要采用EasyUI的前端界面处理技术,走MVC的技术路线,在重 ...

  4. 使用Json实体类构建菜单数据

    基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开发框 ...

  5. JAVA递归生成树形菜单

    递归生成一个如图的菜单,编写两个类数据模型Menu.和创建树形的MenuTree.通过以下过程实现: 1.首先从菜单数据中获取所有根节点. 2.为根节点建立次级子树并拼接上. 3.递归为子节点建立次级 ...

  6. (转)基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据

    http://www.cnblogs.com/wuhuacong/p/3669708.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...

  7. 原生js实现 vue的数据双向绑定

    原生js实现一个简单的vue的数据双向绑定 vue是采用数据劫持结合发布者-订阅者模式的方式,通过Object.defineProperty()来劫持各个属性的setter,getter,在数据变动时 ...

  8. TreeView递归绑定无限分类数据

    TreeView递归绑定无限分类数据 实现一个动态绑定,无限级分类数据时,需要将数据绑定到TreeView控件,分类表的结构是这样的: 字段 类型 Id int ParentId int Name N ...

  9. 详解vue的数据binding原理

    自从angular火了以后,各种mv*框架喷涌而出,angular虽然比较火,但是他的坑还是蛮多的,还有许多性能问题被人们吐槽.比如坑爹的脏检查机制,数据binding是受人喜爱的,脏检查就有点…性能 ...

随机推荐

  1. java有关 String char 常见问题 编辑中

    1 输入输出有关 Scanner 的next()方法 返回值是String 所以尝试获得char时 应该用input.next().charAt[0] 2 空值 String 中null是指 对象引用 ...

  2. batch 常用命令

    1 echo 和 @ 回显命令 @ # 关闭单行回显 echo off # 从下一行开始关闭回显 @echo off # 从本行开始关闭回显,一般批处理第一行都是这个 echo on # 从下一行开始 ...

  3. Python异常处理总结

    一.何谓异常处理 在我们调试程序时,经常不可避免地出现意料之外的情况,导致程序不得不停止运行,然后提示大堆提示信息,大多是这种情况都是由异常引起的.异常的出现一方面是因为写代码时粗心导致的语法错误,这 ...

  4. python监控机器(第1版)

    # coding:utf-8 import configparser import logging import os import psutil import ctypes import platf ...

  5. MySQL 的数据目录

    MySQL里面有4个数据库是属于MySQL自带的系统数据库: mysql 这个数据库贼核心,它存储了MySQL的用户账户和权限信息,一些存储过程.事件的定义信息,一些运行过程中产生的日志信息,一些帮助 ...

  6. python 包以及循环导入

    包的认识 包通过文件夹来管理一系列功能相近的模块 包:一系列模块的集合体重点:包中一定有一个专门用来管理包中所有模块的文件包名:存放一系列模块的文件夹名字包名(包对象)存放的是管理模块的那个文件的地址 ...

  7. vue cli使用融云实现聊天

    公司有个项目要实现一个聊天功能,需求如下图,略显随意 公司最终选择融云这个吊炸天的即时通信,文档详细的一匹,刚开始看文档感觉很详细实现起来也不麻烦,有很多开源的demo可以在线演示和下载 不过我们的项 ...

  8. 高新兴 ME3630-W 4G 模块 Android 平台适配

    2019-04-26 关键字:高新兴 ME3630-W 适配.rk3128 移植 4G 模块 本篇文章系笔者在移植 高新兴物联 ME3630-W 4G 模块到运行着 Android4.4 操作系统的 ...

  9. P1339 [USACO09OCT]热浪Heat Wave

    我太lj了,所以趁着夜色刷了道最短路的水题....然后,,我炸了. 题目描述: The good folks in Texas are having a heatwave this summer. T ...

  10. iPhone 系统刷机

    1. 下载好固件(爱思 或者 pp助手) e.g. http://jailbreak.25pp.com/gujian/ 2. 将电脑与手机连接上,弹出iTunes软件即可 3. 长按手机电源键 关闭手 ...