|
|
|
@ -1661,9 +1661,8 @@ and others) and is equivalent to `required=false`. |
|
|
|
See "`Any other argument`" later in this table. |
|
|
|
See "`Any other argument`" later in this table. |
|
|
|
|
|
|
|
|
|
|
|
| `Errors`, `BindingResult` |
|
|
|
| `Errors`, `BindingResult` |
|
|
|
| For access to errors from validation and data binding for a command object |
|
|
|
| For access to errors from validation and data binding for a command object, i.e. a |
|
|
|
(that is, a `@ModelAttribute` argument) or errors from the validation of a `@RequestBody` or |
|
|
|
`@ModelAttribute` argument. An `Errors`, or `BindingResult` argument must be declared |
|
|
|
`@RequestPart` argument. An `Errors`, or `BindingResult` argument must be declared |
|
|
|
|
|
|
|
immediately after the validated method argument. |
|
|
|
immediately after the validated method argument. |
|
|
|
|
|
|
|
|
|
|
|
| `SessionStatus` + class-level `@SessionAttributes` |
|
|
|
| `SessionStatus` + class-level `@SessionAttributes` |
|
|
|
@ -2318,24 +2317,19 @@ you can declare a concrete target `Object`, instead of `Part`, as the following |
|
|
|
<1> Using `@RequestPart` to get the metadata. |
|
|
|
<1> Using `@RequestPart` to get the metadata. |
|
|
|
==== |
|
|
|
==== |
|
|
|
|
|
|
|
|
|
|
|
You can use `@RequestPart` combination with `javax.validation.Valid` or Spring's |
|
|
|
You can use `@RequestPart` in combination with `javax.validation.Valid` or Spring's |
|
|
|
`@Validated` annotation, which causes Standard Bean Validation to be applied. |
|
|
|
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation |
|
|
|
By default, validation errors cause a `WebExchangeBindException`, which is turned |
|
|
|
errors lead to a `WebExchangeBindException` that results in a 400 (BAD_REQUEST) response. |
|
|
|
into a 400 (`BAD_REQUEST`) response. Alternatively, you can handle validation errors locally |
|
|
|
The exception contains a `BindingResult` with the error details and can also be handled |
|
|
|
within the controller through an `Errors` or `BindingResult` argument, as the following example shows: |
|
|
|
in the controller method by declaring the argument with an async wrapper and then using |
|
|
|
|
|
|
|
error related operators: |
|
|
|
|
|
|
|
|
|
|
|
==== |
|
|
|
==== |
|
|
|
[source,java,indent=0] |
|
|
|
[source,java,indent=0] |
|
|
|
[subs="verbatim,quotes"] |
|
|
|
[subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@PostMapping("/") |
|
|
|
public String handle(@Valid @RequestPart("meta-data") Mono<MetaData> metadata) { |
|
|
|
public String handle(@Valid @RequestPart("meta-data") MetaData metadata, <1> |
|
|
|
// use one of the onError* operators... |
|
|
|
BindingResult result) { <2> |
|
|
|
|
|
|
|
// ... |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
|
|
|
|
<1> Using a `@Valid` annotation. |
|
|
|
|
|
|
|
<2> Using a `BindingResult` argument. |
|
|
|
|
|
|
|
==== |
|
|
|
==== |
|
|
|
|
|
|
|
|
|
|
|
To access all multipart data as a `MultiValueMap`, you can use `@RequestBody`, |
|
|
|
To access all multipart data as a `MultiValueMap`, you can use `@RequestBody`, |
|
|
|
@ -2407,20 +2401,18 @@ You can use the <<webflux-config-message-codecs>> option of the <<webflux-config |
|
|
|
configure or customize message readers. |
|
|
|
configure or customize message readers. |
|
|
|
|
|
|
|
|
|
|
|
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's |
|
|
|
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's |
|
|
|
`@Validated` annotation, which causes Standard Bean Validation to be applied. |
|
|
|
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation |
|
|
|
By default, validation errors cause a `WebExchangeBindException`, which is turned |
|
|
|
errors cause a `WebExchangeBindException`, which results in a 400 (BAD_REQUEST) response. |
|
|
|
into a 400 (`BAD_REQUEST`) response. Alternatively, you can handle validation errors locally |
|
|
|
The exception contains a `BindingResult` with error details and can be handled in the |
|
|
|
within the controller through an `Errors` or a `BindingResult` argument. The following |
|
|
|
controller method by declaring the argument with an async wrapper and then using error |
|
|
|
example uses a `BindingResult` argument`: |
|
|
|
related operators: |
|
|
|
|
|
|
|
|
|
|
|
==== |
|
|
|
==== |
|
|
|
[source,java,indent=0] |
|
|
|
[source,java,indent=0] |
|
|
|
[subs="verbatim,quotes"] |
|
|
|
[subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@PostMapping("/accounts") |
|
|
|
public void handle(@Valid @RequestBody Mono<Account> account) { |
|
|
|
public void handle(@Valid @RequestBody Account account, BindingResult result) { |
|
|
|
// use one of the onError* operators... |
|
|
|
// ... |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
---- |
|
|
|
==== |
|
|
|
==== |
|
|
|
|
|
|
|
|
|
|
|
|