Writing a blog for the first time, kwon as notes, I am also learning Java. Welcome to correct any mistakes.
Sys_menu = sys_menu = sys_menu = sys_menu = sys_menu
/* Navicat MySQL Data Transfer
Source Server: ************** Source Server Version: 50721 Source Host: 10.18.3.200:13306 Source Database: iotCard
Target Server Type : MYSQL Target Server Version : 50721 File Encoding : 65001
Date: 2018-07-09 09:20:35 */
SET FOREIGN_KEY_CHECKS=0;
— Table structure for sys_menu
DROP TABLE IF EXISTS sys_menu; CREATE TABLE sys_menu (id bigint(11) NOT NULL, parenTID Bigint (11) NOT NULL COMMENT ‘parent node id’, Resourcetype varchar(255) COLLATE UTf8_bin DEFAULT NULL COMMENT ‘Resource file type ‘, Resouceid bigint(20) NOT NULL COMMENT ‘表 示 ‘, Resourcename varchar(255) COLLATE UTf8_bin DEFAULT NULL COMMENT ‘File name ‘, Resourcedesc varchar(255) COLLATE UTf8_bin DEFAULT NULL COMMENT ‘Sort the resource file ‘, Resourceurl varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT ‘Resource file path ‘, Resourceicon varchar(255) COLLATE UTf8_bin DEFAULT NULL COMMENT ‘Resource file icon ‘, sortnum bigint(11) DEFAULT NULL, regrant varchar(255) COLLATE utf8_bin DEFAULT NULL, create_time datetime DEFAULT NULL, create_by varchar(32) COLLATE utf8_bin DEFAULT NULL, update_time datetime DEFAULT NULL, update_by varchar(32) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
— Records of sys_menu
INSERT INTO sys_menu VALUES (‘1’, ‘0’, ‘/view/ SUGARgroup /console’, ‘1’, ‘front-end engineering scaffold ‘, NULL, NULL, NULL, null, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 2 ‘, ‘1’, ‘1’, ‘1000’, ‘account overview, null,’. / index. Html# accountOverview/accountOverview ‘, ‘Home’, ‘2110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘3’, ‘1’, ‘1’, ‘1100’, ‘number management ‘,’ original account ‘, ‘./index.html#/common/building’, ‘People’, ‘3110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘4’, ‘3’, ‘1’, ‘1101’, ‘phoneApply ‘, null, ‘./index.html#/phoneManage/phoneApply ‘, null, ‘3111’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘5’, ‘3’, ‘1’, ‘1102’, null, ‘./index.html#/phoneManage/phoneHandle’, ‘3112’, ‘0’, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 6 ‘, ‘3’, ‘1’, ‘1103’, ‘number query’, ‘, ‘. / index. Html# phoneManage/phoneQuery ‘, ‘, ‘3113’, ‘0’, ‘2018-06-25 14:04:29’, ‘hsy’, ‘2018-06-25 14:04:42’, ‘hsy’); INSERT INTO sys_menu VALUES (‘7’, ‘1’, ‘1’, ‘1200’, ‘user data ‘,’ original account ‘, ‘./index.html#/common/building’, ‘People’, ‘4110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘8’, ‘7’, ‘1’, ‘1201’, ‘user ‘, null, ‘./index.html#/userData/userVolume’, null, ‘4111’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘9’, ‘1’, ‘1’, ‘1300’, ‘traffic usage ‘,’ original account ‘, ‘./index.html#/flowUsage/flowUsage’, ‘People’, ‘5110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (’10’, ‘1’, ‘1’, ‘1400’, ‘user Settings ‘,’ original account ‘, ‘./index.html#/common/building’, ‘People’, ‘6110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 11 ‘, ’10’, ‘1’, ‘1401’, ‘upload enterprise information, null,’. / index. Html# userSetting/enterpriseInfoAdd ‘, null, ‘6111’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 12 ‘, ’10’, ‘1’, ‘1402’, ‘look at enterprise information, null,’. / index. Html# userSetting/enterpriseInfoView ‘, null, ‘6112’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 13 ‘, ’10’, ‘1’, ‘1403’, ‘password’ null ‘. / index. Html# userSetting/passwordSetting ‘, null, ‘6113’, ‘0’, null, null, null, null); INSERT INTO sys_menu VALUES (’15’, ‘1’, ‘1’, ‘1500’, ‘./index.html#/uploadData/uploadData’, ‘People’, ‘7110’, ‘1’, null, null, null, null); INSERT INTO sys_menu VALUES (‘ 16 ‘, ‘1’, ‘1’, ‘1600’, ‘the message center, null,’. / index. Html# messageCenter/messageCenter ‘, null, null, null, null, null, null, null);
Mybatis generates DAO, Entity (bean, Model), and mapper files in reverse.
The Bean (Model, Entity) layer
SysMenu. Class public class SysMenu implements Serializable {private static Final Long serialVersionUID = 1L;
private Long id;
private Long parentid;
private String resourcetype;
private Long resouceid;
private String resourcename;
private String resourcedesc;
private String resourceurl;
private String resourceicon;
private Long sortnum;
private String regrant;
private Date createTime;
private String createBy;
private Date updateTime;
private String updateBy;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getParentid() {
return parentid;
}
public void setParentid(Long parentid) {
this.parentid = parentid;
}
public String getResourcetype() {
return resourcetype;
}
public void setResourcetype(String resourcetype) {
this.resourcetype = resourcetype == null ? null : resourcetype.trim();
}
public Long getResouceid() {
return resouceid;
}
public void setResouceid(Long resouceid) {
this.resouceid = resouceid;
}
public String getResourcename() {
return resourcename;
}
public void setResourcename(String resourcename) {
this.resourcename = resourcename == null ? null : resourcename.trim();
}
public String getResourcedesc() {
return resourcedesc;
}
public void setResourcedesc(String resourcedesc) {
this.resourcedesc = resourcedesc == null ? null : resourcedesc.trim();
}
public String getResourceurl() {
return resourceurl;
}
public void setResourceurl(String resourceurl) {
this.resourceurl = resourceurl == null ? null : resourceurl.trim();
}
public String getResourceicon() {
return resourceicon;
}
public void setResourceicon(String resourceicon) {
this.resourceicon = resourceicon == null ? null : resourceicon.trim();
}
public Long getSortnum() {
return sortnum;
}
public void setSortnum(Long sortnum) {
this.sortnum = sortnum;
}
public String getRegrant() {
return regrant;
}
public void setRegrant(String regrant) {
this.regrant = regrant == null ? null : regrant.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy == null ? null : createBy.trim();
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy == null ? null : updateBy.trim();
}
Copy the code
}
Public Class SysMenuTree extends SysMenu implements Serializable {SysMenuTree implements Serializable {
private List<SysMenuTree> children;
public List<SysMenuTree> getChildren() {
return children;
}
public void setChildren(List<SysMenuTree> children) {
this.children = children;
}
Copy the code
}
SysMenuMapper. Class public interface SysMenuMapper {List selectAllSysMenu(); }
Public interface SysMenuService {List selectAllSysMenu(); }
Service implementation layer:
serviceImpl @Service @Transactional(rollbackFor = Exception.class) public class SysMenuServiceImpl implements SysMenuService {
@Resource
SysMenuMapper sysMenuMapper;
@Override
public List<sysMenu> selectAllSysMenu() {
// TODO Auto-generated method stub
return sysMenuMapper.selectAllSysMenu();
}
Copy the code
}
Next comes the Util package, and this is mainly the code that completes the recursive generation of the menu tree. MenuTreeUtil.class /**
-
@author huangshiyou
-
@description: Generates json for foreground tree structure
-
@Date: Created in 2018/6/26 12:37
-
@Modified By: */ public class MenuTreeUtil {//oreginSysMenu Tree menu raw data public static Map getMenuTree(List oreginSysMenu) throws Exception{RsTreeMenu = new HashMap(); SysMenuTree sysMenuTree = new SysMenuTree(); Parentid=0 for (SysMenu SysMenu: oreginSysMenu) { if(sysMenu.getParentid() == 0){ sysMenuTree = copyCMenuToMenuTree(sysMenu); SetChildren (getChild(sysmenutree.getid (),oreginSysMenu))); RsTreeMenu.put(“root”,sysMenuTree); return RsTreeMenu; }
private static List getChild(Long id, List oreginSysMenu) { List childList = new ArrayList<>(); if(booleanHasChildMenu(id,oreginSysMenu)){ for (SysMenu sysMenu: OreginSysMenu){// get all secondary menus if(sysmenu. getParentid().equals(id)){SysMenuTree SysMenuTree = copyCMenuToMenuTree(sysMenu); if(booleanHasChildMenu(sysMenuTree.getId(),oreginSysMenu)){ List child = getChild(sysMenu.getId(), oreginSysMenu); sysMenuTree.setChildren(child); }else{ ArrayList arrayList = new ArrayList(); sysMenuTree.setChildren(arrayList); } childList.add(sysMenuTree); } } } return childList; } public static Boolean booleanHasChildMenu(Long PID, List oreginSysMenu){Boolean flag = false; breakRs: for (SysMenu sysMenu: oreginSysMenu) { if(pid.equals(sysMenu.getParentid())){ flag = true; break breakRs; } } return flag; } public static SysMenuTree copyCMenuToMenuTree(SysMenu SysMenu){SysMenuTree rootSysMenuTree = new SysMenuTree(); SysMenuTree rootSysMenuTree = new SysMenuTree(); rootSysMenuTree.setId(sysMenu.getId()); rootSysMenuTree.setResouceid(sysMenu.getResouceid()); rootSysMenuTree.setParentid(sysMenu.getParentid()); rootSysMenuTree.setResourceicon(sysMenu.getResourceicon()); rootSysMenuTree.setRegrant(sysMenu.getRegrant()); rootSysMenuTree.setResourcedesc(sysMenu.getResourcedesc()); rootSysMenuTree.setResourcename(sysMenu.getResourcename()); rootSysMenuTree.setResourcetype(sysMenu.getResourcetype()); rootSysMenuTree.setResourceurl(sysMenu.getResourceurl()); rootSysMenuTree.setSortnum(sysMenu.getSortnum()); return rootSysMenuTree; }}
The controller layer calls **
-
@author huangshiyou
-
@description: Navigation page menu get
-
@Date: Created in 2018/6/25 11:27
-
@Modified By: */ @Controller public class SysMenuController { Logger logger = LoggerFactory.getLogger(this.class);
@Autowired SysMenuService sysMenuService;
@RequestMapping(value = “/sysMenu/menuList”, method = RequestMethod.GET) @ResponseBody public String getMenuList() throws Exception { return MenuTreeUtil.getMenuTree(sysMenuService.selectAllSysMenu); }}
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — get the json format string for: {” root “: {” children” : [{” children “: [],” id “: “2”, “parentid”: “1”, “regrant”: “1”, “resouceid”: “1000”, “resourceicon”: “Home”, “resourcename”: “Account overview”, “resourcetype” : “1”, “resourceurl” : “. / index. Html# accountOverview/accountOverview “, “sortnum” : “2110” }, { “children”: [{ “children”: [], “id”: “4”, “parentid”: “3”, “regrant”: “1”, “resouceid”: “1101”, “resourcename”: “number application “,” resourceType “: “1”, “resourceURL “: “./index.html#/phoneManage/phoneApply”, “sortnum”: “3111” }, { “children”: [], “id”: “5”, “parentid”: “3”, “regrant”: “0”, “resouceid”: “1102”, “resourceicon”: “”, “resourcename”: “number operation “,” resourceType “: “1”, “resourceURL “: “./index.html#/phoneManage/phoneHandle”, “sortnum”: “3112” }, { “children”: [], “id”: “6”, “parentid”: “3”, “regrant”: “0”, “resouceid”: “1103”, “resourcedesc”: “”, “resourceicon”: “”, “resourcename”: “number query “,” resourceType “: “1”, “resourceURL “: “./index.html#/phoneManage/phoneQuery”, “sortnum”: “3113” } ], “id”: “3”, “parentid”: “1”, “regrant”: “1”, “resouceid”: “1100”, “resourcedesc”: “original account “, “resourceicon”: “People”, “resourcename”:” number management “, “resourceType “: “1”,” resourceURL “: “./index.html#/common/building”, “sortnum”: “3110” }, { “children”: [{ “children”: [], “id”: “8”, “parentid”: “7”, “regrant”: “1”, “resouceID “: “1201”, “resourcename”:” Number of users “, “resourceType “: “1”,” resourceURL “: “./index.html#/userData/userVolume”, “sortnum”: “4111” }], “id”: “7”, “parentid”: “1”, “regrant”: “1”, “resouceid”: “1200”, “resourcedesc”: “original account “, “resourceicon”: “People”, “resourcename”:” user data “, “resourceType “: “1”,” resourceURL “: “./index.html#/common/building”, “sortnum”: “4110” }, { “children”: [], “id”: “9”, “parentid”: “1”, “regrant”: “1”, “resouceID “: “1300”, “resourcedesc”:” original account “, “resourceicon”: “People”, “resourcename”: “Traffic usage “,” resourceType “: “1”, “resourceurl”: “./index.html#/flowUsage/flowUsage”, “sortnum”: “5110” }, { “children”: [{ “children”: [], “id”: “11”, “parenTID “: “10”, “regrant”: “1”,” resouceID “: “1401”, “resourcename”: “Upload enterprise information “,” resourceType “: “1”, “resourceurl”: “./index.html#/userSetting/enterpriseInfoAdd”, “sortnum”: “6111” }, { “children”: [], “id”: “12”, “parenTID “: “10”, “regrant”: “1”,” resouceID “: “1402”, “resourcename”: “View enterprise information “,” resourceType “: “1”, “resourceurl”: “./index.html#/userSetting/enterpriseInfoView”, “sortnum”: “6112” }, { “children”: [], “id”: “13”, “parenTID “: “10”, “regrant”: “0”,” resouceID “: “1403”, “resourcename”: “Password setting “,” resourceType “: “1”, “resourceurl”: “./index.html#/userSetting/passwordSetting”, “sortnum”: “6113” } ], “id”: “10”, “parentid”: “1”, “regrant”: “1”, “resouceID “: “1400”, “resourcedesc”:” original account “, “resourceicon”: “People”, “resourcename”: /index.html#/common/building”, “sortnum”: “6110”}, {“children”: [], “id”, “15”, “parentid” : “1”, “regrant” : “1”, “resouceid” : “1500”, “resourcedesc” : “the original account”, “resourceicon” : “People”, “resourcename”: “data file upload “,” resourceType “: “1”, “resourceURL “: “./index.html#/uploadData/uploadData”, “sortnum”: “7110” }, { “children”: [], “id”: “16”, “parentid”: “1”, “resouceid”: “1600”, “resourcename”: “Message center “,” resourceType “: “1”, “resourceURL “: “./index.html#/messageCenter/messageCenter” } ], “id”: “1”, “parentid”: “0”, “resouceid”: “1”, “resourcename”: “Front-end engineering scaffolding “,” resourceType “: “/view/ Sugargroup /console”}}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --. Harassment is welcome if there is something wrong. Or write me back, or email me at [email protected].Copy the code