In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Java how to achieve the rights management system, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Springboot+mybatis uses a rights management system implemented by aspect-oriented programming (AOP). A total of five modules, role management, menu management, laboratory management, student management, administrator management.
Role management is divided into a super administrator, editing permissions. Menu management displays links and edits for each management. Laboratory management has excel import, the total number of people signed in. Student management has excel import. Additions, deletions, modifications and queries can be realized in each part.
Background role Management Controller:
/ * * background role management controller * @ author yy * * / @ RequestMapping ("/ admin/role") @ Controllerpublic class RoleController {private Logger log = LoggerFactory.getLogger (RoleController.class); @ Autowired private MenuService menuService; @ Autowired private OperaterLogService operaterLogService; @ Autowired private RoleService roleService / * * Paging search for role list * @ param model * @ param role * @ param pageBean * @ return * / @ RequestMapping (value= "/ list") public String list (Model model,Role role,PageBean pageBean) {model.addAttribute ("title", "role list") Model.addAttribute ("name", role.getName ()); model.addAttribute ("pageBean", roleService.findByName (role, pageBean)); return "admin/role/list" } / * role addition page * @ param model * @ return * / @ RequestMapping (value= "/ add", method=RequestMethod.GET) public String add (Model model) {List findAll = menuService.findAll (); model.addAttribute ("topMenus", MenuUtil.getTopMenus (findAll)) Model.addAttribute ("secondMenus", MenuUtil.getSecondMenus (findAll)); model.addAttribute ("thirdMenus", MenuUtil.getThirdMenus (findAll)); return "admin/role/add" } / * role addition form submission process * @ param role * @ return * / @ RequestMapping (value= "/ add" Method=RequestMethod.POST) @ ResponseBody public Result add (Role role) {/ / use the unified verification entity method to verify whether it is legal CodeMsg validate = ValidateEntityUtil.validate (role) If (validate.getCode ()! = CodeMsg.SUCCESS.getCode ()) {return Result.error (validate);} if (roleService.save (role) = = null) {return Result.error (CodeMsg.ADMIN_ROLE_ADD_ERROR) } log.info ("add role [" + role+ "]"); operaterLogService.add ("add role [" + role.getName () + "]"); return Result.success (true) The role editing page * @ param id * @ param model * @ return * / @ RequestMapping (value= "/ edit", method=RequestMethod.GET) public String edit (@ RequestParam (name= "id", required=true) Long id,Model model) {List findAll = menuService.findAll () Model.addAttribute ("topMenus", MenuUtil.getTopMenus (findAll)); model.addAttribute ("secondMenus", MenuUtil.getSecondMenus (findAll)); model.addAttribute ("thirdMenus", MenuUtil.getThirdMenus (findAll)); Role role = roleService.find (id); model.addAttribute ("role", role) Model.addAttribute ("authorities", JSONArray.toJSON (role.getAuthorities ()). ToString ()); return "admin/role/edit" } / * * role modification form submission process * @ param request * @ param role * @ return * / @ RequestMapping (value= "/ edit" Method=RequestMethod.POST) @ ResponseBody public Result edit (Role role) {/ / use the unified verification entity method to verify whether it is legal CodeMsg validate = ValidateEntityUtil.validate (role) If (validate.getCode ()! = CodeMsg.SUCCESS.getCode ()) {return Result.error (validate);} Role existRole = roleService.find (role.getId ()); if (existRole = = null) {return Result.error (CodeMsg.ADMIN_ROLE_NO_EXIST) } existRole.setName (role.getName ()); existRole.setRemark (role.getRemark ()); existRole.setStatus (role.getStatus ()); existRole.setAuthorities (role.getAuthorities ()) If (roleService.save (existRole) = = null) {return Result.error (CodeMsg.ADMIN_ROLE_EDIT_ERROR);} log.info ("Edit role [" + role+ "]"); operaterLogService.add ("Edit role [" + role.getName () + "]"); return Result.success (true) } / * Delete roles * @ param request * @ param id * @ return * / @ RequestMapping (value= "delete", method=RequestMethod.POST) @ ResponseBody public Result delete (@ RequestParam (name= "id", required=true) Long id) {try {roleService.delete (id) } catch (Exception e) {/ / TODO: handle exception return Result.error (CodeMsg.ADMIN_ROLE_DELETE_ERROR);} log.info ("Edit role ID [" + id+ "]"); operaterLogService.add ("Delete role ID [" + id+ "]") Return Result.success (true);}}
Background user management controller:
/ * * background user management controller * @ author yy * * / @ RequestMapping ("/ admin/user") @ Controllerpublic class UserController {@ Autowired private UserService userService; @ Autowired private RoleService roleService; @ Autowired private OperaterLogService operaterLogService / * * user list page * @ param model * @ param user * @ param pageBean * @ return * / @ RequestMapping (value= "/ list") public String list (Model model,User user,PageBean pageBean) {model.addAttribute ("title", "user list") Model.addAttribute ("username", user.getUsername ()); model.addAttribute ("pageBean", userService.findList (user, pageBean)); return "admin/user/list" } / * add user page * @ param model * @ return * / @ RequestMapping (value= "/ add", method=RequestMethod.GET) public String add (Model model) {model.addAttribute ("roles", roleService.findAll ()); return "admin/user/add" } / * user adds form submission process * @ param user * @ return * / @ RequestMapping (value= "/ add" Method=RequestMethod.POST) @ ResponseBody public Result add (User user) {/ / use the unified verification entity method to verify whether it is legal CodeMsg validate = ValidateEntityUtil.validate (user) If (validate.getCode ()! = CodeMsg.SUCCESS.getCode ()) {return Result.error (validate);} if (user.getRole ()) = = null | | user.getRole () .getId () = = null) {return Result.error (CodeMsg.ADMIN_USER_ROLE_EMPTY) } / / determine whether the user name exists if (userService.isExistUsername (user.getUsername (), 0l)) {return Result.error (CodeMsg.ADMIN_USERNAME_EXIST) } / / until this shows that everything meets the requirements, add if to the database (userService.save (user) = = null) {return Result.error (CodeMsg.ADMIN_USE_ADD_ERROR);} operaterLogService.add ("add user, user name:" + user.getUsername ()) Return Result.success (true) } / * user editing page * @ param model * @ return * / @ RequestMapping (value= "/ edit", method=RequestMethod.GET) public String edit (Model model,@RequestParam (name= "id", required=true) Long id) {model.addAttribute ("roles", roleService.findAll ()) Model.addAttribute ("user", userService.find (id)); return "admin/user/edit" } / * Edit user information form submission process * @ param user * @ return * / @ RequestMapping (value= "/ edit" Method=RequestMethod.POST) @ ResponseBody public Result edit (User user) {/ / use the unified verification entity method to verify whether it is legal CodeMsg validate = ValidateEntityUtil.validate (user) If (validate.getCode ()! = CodeMsg.SUCCESS.getCode ()) {return Result.error (validate);} if (user.getRole ()) = = null | | user.getRole () .getId () = = null) {return Result.error (CodeMsg.ADMIN_USER_ROLE_EMPTY) } if (user.getId () = = null | | user.getId () .longValue ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.