/** 更新 */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Role role, RedirectAttributes redirectAttributes) { if (!isValid(role)) { return ERROR_VIEW; } Role pRole = roleService.find(role.getId()); if (pRole == null || pRole.getIsSystem()) { return ERROR_VIEW; } roleService.update(role, "isSystem", "admins"); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
/** 删除 */ @RequestMapping(value = "/delete", method = RequestMethod.POST) public @ResponseBody Message delete(Long[] ids) { if (ids != null) { for (Long id : ids) { Role role = roleService.find(id); if (role != null && (role.getIsSystem() || (role.getAdmins() != null && !role.getAdmins().isEmpty()))) { return Message.error("admin.role.deleteExistNotAllowed", role.getName()); } } roleService.delete(ids); } return SUCCESS_MESSAGE; }
/** 保存 */ @RequestMapping(value = "/save", method = RequestMethod.POST) public String save(Role role, RedirectAttributes redirectAttributes) { if (!isValid(role)) { return ERROR_VIEW; } role.setIsSystem(false); role.setAdmins(null); roleService.save(role); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
/** 列表 */ @RequestMapping(value = "/list", method = RequestMethod.GET) public String list(Pageable pageable, ModelMap model) { model.addAttribute("page", roleService.findPage(pageable)); return "/admin/role/list"; }
/** 编辑 */ @RequestMapping(value = "/edit", method = RequestMethod.GET) public String edit(Long id, ModelMap model) { model.addAttribute("role", roleService.find(id)); return "/admin/role/edit"; }