コード例 #1
0
  @RequestMapping(value = "/admin/user/delete/{id}")
  public String deleteUser(@PathVariable("id") int id, HttpSession session) {

    User user = userService.findEntityById(id);
    if (user != null) {
      try {
        userService.delete(user);
      } catch (RuntimeException re) {
        pageFrameworkService.setFlashMessage(session, re.getMessage());
        pageFrameworkService.setIsRedirect(session, Boolean.TRUE);
        return "redirect:/admin/user/show/" + id;
      }
    } else {
      pageFrameworkService.setFlashMessage(session, "No User with that id");
      pageFrameworkService.setIsRedirect(session, Boolean.TRUE);
    }
    return "redirect:/admin/user/list";
  }
コード例 #2
0
  @RequestMapping(value = "/admin/user/save", method = RequestMethod.POST)
  public String saveUser(
      @ModelAttribute("user") User user, BindingResult result, Model model, HttpSession session) {

    userService.save(user);

    try {
      if (user.getDateCreated() == null) user.setDateCreated(new Date());
      user.setLastUpdated(new Date());

      userService.save(user);
    } catch (RuntimeException re) {
      pageFrameworkService.setFlashMessage(session, re.getMessage());
      pageFrameworkService.setIsRedirect(session, Boolean.TRUE);
      return "redirect:/admin/user/list";
    }
    return "redirect:/admin/user/list";
  }