菜单管理又称为资源管理,是系统资源对外的表现形式。本模块主要是实现对菜
单进行添加、修改、查询、删除等操作
@Controller
public class PageController {
/*
//该代码通用性不够强
@GetMapping("/menu/menu_list")
public String doMenuUI(){
return "sys/menu_list";
}
*/
//通过rest风格的url处理客户端的ui请求
@GetMapping("/{module}/{moduleUI}")
public String doModuleUI(@PathVariable String moduleUI){
return "sys/"+moduleUI;
}
说明:点击菜单按钮,回显menu_list页面的跳转
package cn.tedu.dbadmin.dao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
@Mapper
public interface SysMenuDao {
List
package cn.tedu.dbadmin.service;
import java.util.List;
import java.util.Map;
public interface SysMenuService {
List
package cn.tedu.dbadmin.service;
import cn.tedu.dbadmin.dao.SysMenuDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class SysMenuServiceImpl implements SysMenuService {
@Autowired
private SysMenuDao sysMenuDao;
@Override
public List
@RestController
public class SysMenuController {
@Autowired
private SysMenuService sysMenuService;
@GetMapping("/menu/doFindObjects")
public JsonResult doFindObjects() throws InterruptedException {
return new JsonResult(sysMenuService.findObjects());
}
}
Title
The Menu Page
id
name
parentName
Data is loading ....
Title
The Menu Page
基于用户在列表页面上选择的的菜单记录 ID,执行删除操作,本次删除业务实现中,首先
要基于 id 判断当前菜单是否有子菜单,假如有子菜单则不允许删除,没有则先删除菜单角
色关系数据,然后再删除菜单自身信息。
package cn.tedu.dbadmin.dao;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SysRoleMenuDao {
//基于菜单id删除角色菜单关系
int deleteObjectsByMenuId(Integer id);
}
package cn.tedu.dbadmin.dao;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
@Mapper
public interface SysMenuDao {
List
delete from sys_role_menus
where #{id} = menu_id
delete from sys_menus
where id = #{id};
package cn.tedu.dbadmin.service;
import java.util.List;
import java.util.Map;
public interface SysMenuService {
List
package cn.tedu.dbadmin.service;
import cn.tedu.dbadmin.dao.SysMenuDao;
import cn.tedu.dbadmin.dao.SysRoleMenuDao;
import cn.tedu.dbcommon.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class SysMenuServiceImpl implements SysMenuService {
@Autowired
private SysMenuDao sysMenuDao;
@Autowired
private SysRoleMenuDao sysRoleMenuDao;
@Override
public List
package cn.tedu.dbadmin.controller;
import cn.tedu.dbadmin.service.SysMenuService;
import cn.tedu.dbcommon.pojo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/menu/")
@RestController
public class SysMenuController {
@Autowired
private SysMenuService sysMenuService;
@RequestMapping("doFindObjects")
public JsonResult doFindObjects(){
return new JsonResult(sysMenuService.findObjects());
}
@RequestMapping("doDeleteObject")
public JsonResult doDeleteObject(Integer id){
sysMenuService.deleteObject(id);
return new JsonResult("删除成功");
}
}
package com.cy.pj.common.pojo;
import lombok.Data;
import java.io.Serializable;
@Data
public class Node implements Serializable {
private static final long serialVersionUID = -7022202313802285223L;
private Integer id;
private String name;
private Integer parentId;
}
@Select("select id,name,parentId from sys_menus")
public List findZtreeMenuNodes();
public List findZtreeMenuNodes(){
return sysMenuDao.findZtreeMenuNodes();
}
@GetMapping("/menu/doFindZtreeMenuNodes")
public JsonResult doFindZtreeMenuNodes(){
return new JsonResult(sysMenuService.findZtreeMenuNodes());
}
说明: 实现树结构菜单的页面呈现
Title
package cn.tedu.dbcommon.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysMenu implements Serializable {
private static final long serialVersionUID = 8049305945150183138L;
private Integer id;//菜单id
private String name;//菜单名称
private String url;//菜单URL
private Integer type = 1;
private Integer sort;//菜单序号
private String note;//菜单备注
private Integer parentId;//上级菜单id
private String permission;//授权标识
private String createdUser;//创建用户
private String modifiedUser;//修改用户
private Date createdTime;//创建时间
private Date modifiedTime;//修改时间
}
int insertObject(SysMenu menu);
insert into sys_menus
(name,url,type,sort,note,parentId,permission,
createdTime,modifiedTime,createdUser,modifiedUser)
values
(#{name},#{url},#{type},#{sort},#{note},#{parentId},
#{permission},now(),now(),#{createdUser},#{modifiedUser})
int saveObject(SysMenu entity);
@Override
public int saveObject(SysMenu entity) {
if(entity==null)
throw new IllegalArgumentException("保存对象不能为空");
if(entity.getName()==null||"".equals(entity.getName()))
throw new IllegalArgumentException("菜单名不允许为空");
//........
int rows=sysMenuDao.insertObject(entity);
return rows;
}
@PostMapping("/menu/doSaveObject")
public JsonResult doSaveObject(SysMenu entity){
sysMenuService.saveObject(entity);
return new JsonResult("save ok");
}
int updateObject(SysMenu menu);
update sys_menus
set
name=#{name},
type=#{type},
sort=#{sort},
url=#{url},
parentId=#{parentId},
permission=#{permission},
modifiedUser=#{modifiedUser},
modifiedTime=now()
where id=#{id}
int updateObject(SysMenu entity);
@Override
public int updateObject(SysMenu entity) {
if(entity==null)
throw new IllegalArgumentException("保存对象不能为空");
if(entity.getName()==null||"".equals(entity.getName()))
throw new IllegalArgumentException("菜单名不允许为空");
//........
int rows=sysMenuDao.updateObject(entity);
return rows;
}
@PostMapping("/menu/doUpdateObject")
public JsonResult doUpateObject(SysMenu entity){
sysMenuService.updateObject(entity);
return new JsonResult("update ok");
}