Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the work Management system with Java

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to implement the work management system in Java. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

There are two roles of foreground user and backend administrator:

Front desk user functions are: post part-time, post, view bulletin, personal center, complaints and so on.

Background administrator functions are: user management, part-time management, post management, chat management, advertising management, complaint management, collection management, system management and so on.

Running environment: jdk1.8, tomcat7.0\ 8.5, Eclipse, Mysql5.x.

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: 229

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report