@RequestMapping(method = RequestMethod.GET) public String index(ModelMap map) { for (User u : userService.getUserWithRole()) { System.out.println(u.toString()); } map.addAttribute("users", userService.getUserWithRole()); return "user/index"; }
@RequestMapping(value = "update", method = RequestMethod.POST) public String update( @ModelAttribute(value = "User") User user, @Context HttpServletRequest request) { user.setUserId(Integer.parseInt(request.getParameter("id"))); userService.update(user); return "redirect:/admin/user"; }
@RequestMapping(value = "delete", method = RequestMethod.GET) public String delete( @ModelAttribute(value = "User") User user, @Context HttpServletRequest request) { int userId = Integer.parseInt(request.getParameter("id")); userService.delete(userId); return "redirect:/admin/user"; }
@RequestMapping(value = "edit", method = RequestMethod.GET) public ModelAndView edit( @ModelAttribute(value = "User") User user, @Context HttpServletRequest request) { ModelAndView mv = null; int id = Integer.parseInt(request.getParameter("id")); User u = userService.getByUserId(id); if (u != null) { mv = new ModelAndView("user/edit"); mv.addObject("role", roleService.getByRoleId(u.getRoleId())); mv.addObject("roles", roleService.getAll()); mv.addObject("user", u); } return mv; }
@RequestMapping(value = "save", method = RequestMethod.POST) public String save(@ModelAttribute(value = "User") User user) { userService.insert(user); return "redirect:/admin/user"; }