79357942

Date: 2025-01-15 11:05:40
Score: 1.5
Natty:
Report link

When going over the chaper where validation is set, you also add an argument Error error to your controller methods. Pay attention that error is immediately following your @Valid argument as in the example below. I placed it at first at the end of my args and kept receiving the Whitelable error.

Explanation: Spring matches the injected Errors arg with the preceding @Valid object. If the Errors arg isn’t directly after the @Valid arg, Spring won’t know which object the validation results belong to.

 @PostMapping
public String processTaco(**@Valid Taco taco,  Errors errors,** @ModelAttribute TacoOrder tacoOrder) {
    if(errors.hasErrors()) {
        return "design";
    }

    tacoOrder.addTaco(taco);
    log.info("Processing taco: {}", taco);
    return "redirect:/orders/current";
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Valid
  • User mentioned (0): @Valid
  • User mentioned (0): @Valid
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: lupudeni