/** 保存 */ @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 = "/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; }