I am passing data to two objects from a single html form and in controller I have to use two objects. So, I want to know if I can use the BindingResult for each object in same controller in order to show the errors if it occurred.
Asked
Active
Viewed 393 times
0
-
It would be much helpful if you share some code snippets.Thanks – Shubham Dixit Sep 27 '18 at 05:25
1 Answers
2
If you receive two objects from one form in the controller, you must have two BindingResults beacause one BindingResult contains the result of the validation of the object right before it in the signature of the controller's method.
So your controller should look like that :
@PostMapping("...")
public String handlePost(@Valid Object1 object1, BindingResult result1, @Valid Object2 object2, BindingResult result2) {
Maybe you should have look at this post
Romain Warnan
- 1,022
- 1
- 7
- 13