Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of BindingResult interface in spring MVC?

Tags:

spring-mvc

Is BindingResult useful to bind just exceptions with view, or something else?

what is the exact use of BindingResult?

Or is it useful in binding model attribute with view.

like image 553
JOHND Avatar asked May 02 '12 12:05

JOHND


People also ask

What is the use of @valid annotation in Spring MVC?

The @Valid annotation will tell spring to go and validate the data passed into the controller by checking to see that the integer numberBetweenOneAndTen is between 1 and 10 inclusive because of those min and max annotations.

What is @validated in Spring boot?

@Validated annotation is a class-level annotation that we can use to tell Spring to validate parameters that are passed into a method of the annotated class. and. @Valid annotation on method parameters and fields to tell Spring that we want a method parameter or field to be validated.

What is @valid in Java?

The Java Bean Validation's @Valid constraint annotation makes sure that when an object is validated, the validation recurses to all fields that are annotated with @Valid . This makes it really easy to perform the usually complex task of validating entire object graphs.


1 Answers

Particular example: use a BindingResult object as an argument for a validate method of a Validator inside a Controller.

Then, you can check this object looking for validation errors:

validator.validate(modelObject, bindingResult);   if (bindingResult.hasErrors()) {       // do something   } 
like image 80
Dani Avatar answered Oct 20 '22 19:10

Dani