@RequestMapping(value = "saveRole", method = RequestMethod.POST) public String save( @ModelAttribute @Valid RoleDomain roleDomain, BindingResult bindingResult, HttpServletRequest request, HttpSession session) { if (Strings.isNullOrEmpty(roleDomain.getName())) { bindingResult.rejectValue("name", "", "角色名称不能为空"); return ""; } OsRole osRole = new OsRole(); osRole.setName(roleDomain.getName()); osRole.setRemark(roleDomain.getRemark()); iRoleService.save(osRole, roleDomain.getOsPermissions()); String user = null != session.getAttribute("account") ? String.valueOf(session.getAttribute("account")) : "admin"; StringBuilder stringBuilder = new StringBuilder("管理员[") .append(user) .append("]") .append("创建了角色[") .append(roleDomain.getName()) .append("]"); applicationContext.publishEvent( new LogEvent(this, stringBuilder.toString(), user, request.getRemoteHost())); return "redirect:roles"; }
@RequestMapping(value = "adminRoleInfo/{id}", method = RequestMethod.GET) public String adminRoleInfo( @PathVariable("id") int id, @RequestParam("account") String account, Model model) { List<OsRole> osRoleList = iRoleService.findAll(); List<OsRole> own = iRoleService.findRoleByAdminId(id); StringBuilder stringBuilder = new StringBuilder(";"); for (OsRole osRole : own) { stringBuilder.append(osRole.getId()).append(";"); } model.addAttribute("osRoleList", osRoleList); model.addAttribute("hasRole", stringBuilder.toString()); model.addAttribute("tmpAccount", account); model.addAttribute("tmpId", id); return "admin_role"; }
@RequestMapping(value = "roleInfo/{id}", method = RequestMethod.GET) public String roleInfo(@PathVariable("id") int id, Model model) { OsRole osRole = iRoleService.findOne(id); StringBuilder stringBuilder = new StringBuilder(";"); for (OsPermission osPermission : osRole.getOsPermissions()) { stringBuilder.append(osPermission.getId()).append(";"); } List<OsPermission> osPermissionList = iRoleService.findUnAssignPermission(); model.addAttribute("osRole", osRole); model.addAttribute("osPermissionList", osPermissionList); model.addAttribute("msg", "修改角色"); model.addAttribute("type", "update"); model.addAttribute("hasPermission", stringBuilder.toString()); return "admin_addRole"; }