@@ -8,23 +8,23 @@ Spring MVC has built-in xref:core/validation/validator.adoc[Validation] support
8
8
xref:core/validation/beanvalidation.adoc[Java Bean Validation].
9
9
The validation support works on two levels.
10
10
11
- First, method parameters such as
11
+ First, resolvers for
12
12
xref:web/webmvc/mvc-controller/ann-methods/modelattrib-method-args.adoc[@ModelAttribute],
13
13
xref:web/webmvc/mvc-controller/ann-methods/requestbody.adoc[@RequestBody], and
14
- xref:web/webmvc/mvc-controller/ann-methods/multipart-forms.adoc[@RequestPart] do perform
15
- validation if annotated with Jakarta's `@Valid` or Spring's `@Validated` annotation, and
16
- raise `MethodArgumentNotValidException` in case of validation errors. If you want to handle
17
- the errors in the controller method instead, you can declare an `Errors` or `BindingResult`
18
- method parameter immediately after the validated parameter .
19
-
20
- Second, if {bean-validation-site}[Java Bean Validation] is present _AND_ other method
21
- parameters, e.g. `@RequestHeader`, `@RequestParam`, `@PathVariable` have `@Constraint`
22
- annotations, then method validation is applied to all method arguments, raising
23
- `HandlerMethodValidationException` in case of validation errors. You can still declare an
24
- `Errors` or `BindingResult` after an `@Valid` method parameter, and handle validation
25
- errors within the controller method, as long as there are no validation errors on other
26
- method arguments. Method validation is also applied to the return value if the method
27
- is annotated with `@Valid` or has other `@Constraint` annotations.
14
+ xref:web/webmvc/mvc-controller/ann-methods/multipart-forms.adoc[@RequestPart] method
15
+ parameters perform validation if the parameter has Jakarta's `@Valid` or Spring's
16
+ `@Validated` annotation, and raise `MethodArgumentNotValidException` if necessary.
17
+ Alternatively, you can handle the errors in the controller method by adding an
18
+ `Errors` or `BindingResult` method parameter immediately after the validated one .
19
+
20
+ Second, if {bean-validation-site}[Java Bean Validation] is present _AND_ any method
21
+ parameter has `@Constraint` annotations, then method validation is applied instead,
22
+ raising `HandlerMethodValidationException` if necessary. For this case you can still add
23
+ an `Errors` or `BindingResult` method parameter to handle validation errors within the
24
+ controller method, but if other method arguments have validation errors then
25
+ `HandlerMethodValidationException` is raised instead. Method validation can apply
26
+ to the return value if the method is annotated with `@Valid` or with `@Constraint`
27
+ annotations.
28
28
29
29
You can configure a `Validator` globally through the
30
30
xref:web/webmvc/mvc-config/validation.adoc[WebMvc config], or locally through an
@@ -109,4 +109,4 @@ Kotlin::
109
109
}
110
110
})
111
111
----
112
- ======
112
+ ======
0 commit comments