コード例 #1
0
 @RequestMapping(value = "delete/{id}")
 public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttributes) {
   User user = accountService.getUser(id);
   accountService.deleteUser(id);
   redirectAttributes.addFlashAttribute("message", "删除用户" + user.getLoginName() + "成功");
   return "redirect:/admin/user";
 }
コード例 #2
0
 @RequestMapping(value = "update", method = RequestMethod.POST)
 public String update(
     @Valid @ModelAttribute("user") User user, RedirectAttributes redirectAttributes) {
   accountService.updateUser(user);
   redirectAttributes.addFlashAttribute("message", "更新用户" + user.getLoginName() + "成功");
   return "redirect:/admin/user";
 }
コード例 #3
0
  @RequestMapping(method = RequestMethod.GET)
  public String list(Model model) {
    List<User> users = accountService.getAllUser();
    model.addAttribute("users", users);

    return "account/adminUserList";
  }
コード例 #4
0
 /**
  * 所有RequestMapping方法调用前的Model准备方法, 实现Struts2
  * Preparable二次部分绑定的效果,先根据form的id从数据库查出User对象,再把Form提交的内容绑定到该对象上。
  * 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
  */
 @ModelAttribute
 public void getUser(@RequestParam(value = "id", defaultValue = "-1") Long id, Model model) {
   if (id != -1) {
     model.addAttribute("user", accountService.getUser(id));
   }
 }
コード例 #5
0
 @RequestMapping(value = "update/{id}", method = RequestMethod.GET)
 public String updateForm(@PathVariable("id") Long id, Model model) {
   model.addAttribute("user", accountService.getUser(id));
   return "account/adminUserForm";
 }