Exemplo n.º 1
0
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  public String deleteUser(
      @ModelAttribute("deleteUser") User deleteUser,
      BindingResult result,
      final RedirectAttributes redirectAttr) {
    if (!result.hasErrors()) {
      service.deleteById(deleteUser.getId());
      redirectAttr.addFlashAttribute("success", true);
      redirectAttr.addFlashAttribute("message", "Success delete user!");
    } else {
      redirectAttr.addFlashAttribute("error", true);
      redirectAttr.addFlashAttribute("message", "Can't delete user. Something went wrong.");
    }

    return "redirect:/user";
  }
Exemplo n.º 2
0
  @RequestMapping(value = "/update", method = RequestMethod.POST)
  public String updateUser(
      @ModelAttribute("editUser") User editUser,
      BindingResult result,
      final RedirectAttributes redirectAttr) {
    if (result.hasErrors()) {
      redirectAttr.addFlashAttribute("error", true);
      redirectAttr.addFlashAttribute("message", result.getFieldError().getDefaultMessage());
      return "redirect:/user/edit/" + Long.toString(editUser.getId());
    }
    service.update(editUser);
    redirectAttr.addFlashAttribute("success", true);
    redirectAttr.addFlashAttribute("message", "Success edit user!");

    return "redirect:/user";
  }