Skip to content

Commit f9726ae

Browse files
committed
Update description of web validation in docs
Closes spring-projectsgh-32082
1 parent 199a675 commit f9726ae

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-validation.adoc

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33

44
[.small]#xref:web/webmvc/mvc-controller/ann-validation.adoc[See equivalent in the Servlet stack]#
55

6-
Spring WebFlux has built-in xref:core/validation/validator.adoc[Validation] support for
6+
Spring MVC has built-in xref:core/validation/validator.adoc[Validation] support for
77
`@RequestMapping` methods, including the option to use
88
xref:core/validation/beanvalidation.adoc[Java Bean Validation].
99
The validation support works on two levels.
1010

11-
First, method parameters such as
11+
First, resolvers for
1212
xref:web/webflux/controller/ann-methods/modelattrib-method-args.adoc[@ModelAttribute],
1313
xref:web/webflux/controller/ann-methods/requestbody.adoc[@RequestBody], and
14-
xref:web/webflux/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.
14+
xref:web/webflux/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.
2728

2829
You can configure a `Validator` globally through the
2930
xref:web/webflux/config.adoc#webflux-config-validation[WebMvc config], or locally

framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-validation.adoc

+16-16
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ Spring MVC has built-in xref:core/validation/validator.adoc[Validation] support
88
xref:core/validation/beanvalidation.adoc[Java Bean Validation].
99
The validation support works on two levels.
1010

11-
First, method parameters such as
11+
First, resolvers for
1212
xref:web/webmvc/mvc-controller/ann-methods/modelattrib-method-args.adoc[@ModelAttribute],
1313
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.
2828

2929
You can configure a `Validator` globally through the
3030
xref:web/webmvc/mvc-config/validation.adoc[WebMvc config], or locally through an
@@ -109,4 +109,4 @@ Kotlin::
109109
}
110110
})
111111
----
112-
======
112+
======

0 commit comments

Comments
 (0)