spring-petclinic
spring-petclinic copied to clipboard
Why redirectAttributes.addFlashAttribute next return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;?
@PostMapping("/owners/{ownerId}/edit")
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId,
RedirectAttributes redirectAttributes) {
if (result.hasErrors()) {
redirectAttributes.addFlashAttribute("error", "There was an error in updating the owner.");
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}
owner.setId(ownerId);
this.owners.save(owner);
redirectAttributes.addFlashAttribute("message", "Owner Values Updated");
return "redirect:/owners/{ownerId}";
}
Im looking this code. if client want to see "There was an error in updating the owner.", i think that return "redirect:/owners/{ownerId}";' is right, not VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
I dont understand why use 'redirectAttributes.addFlashAttribute'
Maybe Spring developer probably has a specific intent. Could you check this code?