java实现递归菜单树
本文实例为大家分享了java实现递归菜单树的具体代码,供大家参考,具体内容如下
1.表结构
SETFOREIGN_KEY_CHECKS=0; ------------------------------ --Tablestructureformenu ------------------------------ DROPTABLEIFEXISTS`menu`; CREATETABLE`menu`( `id`int(11)NOTNULLAUTO_INCREMENT, `menu_name`varchar(64)NOTNULLCOMMENT'菜单名称', `order_num`int(11)DEFAULTNULLCOMMENT'菜单顺序', `url`varchar(64)DEFAULTNULLCOMMENT'菜单路径', `pid`varchar(11)DEFAULTNULLCOMMENT'上级Id', `icon`varchar(255)DEFAULTNULLCOMMENT'菜单图标', PRIMARYKEY(`id`) )ENGINE=InnoDBAUTO_INCREMENT=11DEFAULTCHARSET=utf8; ------------------------------ --Recordsofmenu ------------------------------ INSERTINTO`menu`VALUES('1','系统管理','1','','0',null); INSERTINTO`menu`VALUES('2','轨迹查询','2','','0',null); INSERTINTO`menu`VALUES('3','设备信息','3','','0',null); INSERTINTO`menu`VALUES('4','用户信息','1','','1',null); INSERTINTO`menu`VALUES('5','客户信息','2',null,'1',null); INSERTINTO`menu`VALUES('6','用户资料','1',null,'4',null); INSERTINTO`menu`VALUES('7','客户资料','1',null,'5',null); INSERTINTO`menu`VALUES('8','切割机','1',null,'3',null); INSERTINTO`menu`VALUES('9','铲车','2',null,'3',null); INSERTINTO`menu`VALUES('10','割片','1',null,'8',null);
2.菜单实体类
importlombok.Data; importjava.io.Serializable; importjava.util.List; importjavax.persistence.*; /** * *@authorm *@email123456789@qq.com *@date2019-12-1316:54:59 */ @Data @Table(name="menu") publicclassMenuimplementsSerializable{ privatestaticfinallongserialVersionUID=1L; // @Id privateIntegerid; //菜单名称 @Column(name="menu_name") privateStringmenuName; //菜单顺序 @Column(name="order_num") privateIntegerorderNum; //菜单路径 @Column(name="url") privateStringurl; //上级Id @Column(name="pid") privateStringpid; //菜单图标 @Column(name="icon") privateStringicon; //子菜单 @Transient privateList
3.菜单树
/** *获取菜单树 *@return */ publicList
4.测试
{ "status":200, "message":"操作成功", "data":[ { "id":1, "menuName":"系统管理", "orderNum":1, "url":"", "pid":"0", "icon":null, "children":[ { "id":4, "menuName":"用户信息", "orderNum":1, "url":"", "pid":"1", "icon":null, "children":[ { "id":6, "menuName":"用户资料", "orderNum":1, "url":null, "pid":"4", "icon":null, "children":[] } ] }, { "id":5, "menuName":"客户信息", "orderNum":2, "url":null, "pid":"1", "icon":null, "children":[ { "id":7, "menuName":"客户资料", "orderNum":1, "url":null, "pid":"5", "icon":null, "children":[] } ] } ] }, { "id":2, "menuName":"轨迹查询", "orderNum":2, "url":"", "pid":"0", "icon":null, "children":[] }, { "id":3, "menuName":"设备信息", "orderNum":3, "url":"", "pid":"0", "icon":null, "children":[ { "id":8, "menuName":"切割机", "orderNum":1, "url":null, "pid":"3", "icon":null, "children":[ { "id":10, "menuName":"割片", "orderNum":1, "url":null, "pid":"8", "icon":null, "children":[] } ] }, { "id":9, "menuName":"铲车", "orderNum":2, "url":null, "pid":"3", "icon":null, "children":[] } ] } ] }
5.菜单树工具类
菜单树工具类
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。