What is the use of BindingResult interface in spring MVC?

前端 未结 6 1068
梦如初夏
梦如初夏 2020-12-12 18:43

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

what is the exact use of BindingResult?

Or is it usef

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 19:42

    Basically BindingResult is an interface which dictates how the object that stores the result of validation should store and retrieve the result of the validation(errors, attempt to bind to disallowed fields etc)

    From Spring MVC Form Validation with Annotations Tutorial:

    [BindingResult] is Spring’s object that holds the result of the validation and binding and contains errors that may have occurred. The BindingResult must come right after the model object that is validated or else Spring will fail to validate the object and throw an exception.

    When Spring sees @Valid, it tries to find the validator for the object being validated. Spring automatically picks up validation annotations if you have “annotation-driven” enabled. Spring then invokes the validator and puts any errors in the BindingResult and adds the BindingResult to the view model.

提交回复
热议问题