spring-petclinic icon indicating copy to clipboard operation
spring-petclinic copied to clipboard

Why redirectAttributes.addFlashAttribute next return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;?

Open omelet3032 opened this issue 9 months ago • 1 comments

@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?

omelet3032 avatar May 21 '24 08:05 omelet3032