Thymeleaf Neither BindingResult nor plain target object for bean name 'person' available as request attribute
You forgot to add BindingResult
after your @ModelAttribute
:
@RequestMapping(value="/person", method=RequestMethod.POST)
public String contactSubmit(@ModelAttribute Person person, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
//errors processing
}
model.addAttribute("person", person);
return "result";
}
I'm already have answered to question like this :
- html form validation using thymeleaf not working spring boot
Model attribute has to be initialized (using GET method) before calling post method.
In your case you need one more method in controller which does model.addAttribute("person",new Person());
and it has to be called before post.
Refer below link: https://spring.io/guides/gs/handling-form-submission/ OR http://forum.thymeleaf.org/Neither-BindingResult-nor-plain-target-object-for-bean-name-miniDoniie-available-as-request-attribute-td4027859.html
It has GetMapping
as well as PostMapping
in controller.