@ -59,26 +70,71 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
@@ -59,26 +70,71 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
@ -103,19 +97,115 @@ public class RequestParamMapMethodArgumentResolverTests {
@@ -103,19 +97,115 @@ public class RequestParamMapMethodArgumentResolverTests {
| For access to the model that is used in HTML controllers and exposed to templates as
@ -2073,8 +2074,8 @@ To get all matrix variables, you can use a `MultiValueMap`, as the following exa
@@ -2073,8 +2074,8 @@ To get all matrix variables, you can use a `MultiValueMap`, as the following exa
----
====
Note that you need to enable the use of matrix variables. In the MVC Java configuration, you need
to set a `UrlPathHelper` with `removeSemicolonContent=false` through
Note that you need to enable the use of matrix variables. In the MVC Java configuration,
you need to set a `UrlPathHelper` with `removeSemicolonContent=false` through
<<mvc-config-path-matching>>. In the MVC XML namespace, you can set
@ -2084,8 +2085,8 @@ to set a `UrlPathHelper` with `removeSemicolonContent=false` through
@@ -2084,8 +2085,8 @@ to set a `UrlPathHelper` with `removeSemicolonContent=false` through
==== `@RequestParam`
[.small]#<<web-reactive.adoc#webflux-ann-requestparam,Same as in Spring WebFlux>>#
You can use the `@RequestParam` annotation to bind Servlet request parameters (that is, query
parameters or form data) to a method argument in a controller.
You can use the `@RequestParam` annotation to bind Servlet request parameters (that is,
query parameters or form data) to a method argument in a controller.
The following example shows how to do so:
@ -2114,17 +2115,20 @@ The following example shows how to do so:
@@ -2114,17 +2115,20 @@ The following example shows how to do so:
====
By default, method parameters that use this annotation are required, but you can specify that
a method parameter is optional by setting the `@RequestParam` annotation's `required` flag to `false`
or by declaring the argument with an `java.util.Optional` wrapper.
a method parameter is optional by setting the `@RequestParam` annotation's `required` flag to
`false` or by declaring the argument with an `java.util.Optional` wrapper.
Type conversion is automatically applied if the target method parameter type is not
`String`. See <<mvc-ann-typeconversion>>.
Declaring the argument type as an array or list allows for resolving multiple parameter
values for the same parameter name.
When an `@RequestParam` annotation is declared as a `Map<String, String>` or
`MultiValueMap<String, String>` argument, the map is populated with all request
parameters.
`MultiValueMap<String, String>`, without a parameter name specified in the annotation,
then the map is populated with the request parameter values for each given parameter name.
Note that use of `@RequestParam` is optional, (for example, to set its attributes).
Note that use of `@RequestParam` is optional (for example, to set its attributes).
By default, any argument that is a simple value type (as determined by
and is not resolved by any other argument resolver, is treated as if it were annotated
@ -2534,8 +2538,8 @@ after the redirect, attributes from the "`input`" `FlashMap` are automatically a
@@ -2534,8 +2538,8 @@ after the redirect, attributes from the "`input`" `FlashMap` are automatically a
.Matching requests to flash attributes
****
The concept of flash attributes exists in many other web frameworks and has proven to sometimes be
exposed to concurrency issues. This is because, by definition, flash attributes
The concept of flash attributes exists in many other web frameworks and has proven to sometimes
be exposed to concurrency issues. This is because, by definition, flash attributes
are to be stored until the next request. However the very "`next`" request may not be the
intended recipient but another asynchronous request (for example, polling or resource requests),
in which case the flash attributes are removed too early.
@ -2577,16 +2581,21 @@ public class FileUploadController {
@@ -2577,16 +2581,21 @@ public class FileUploadController {
// store the bytes somewhere
return "redirect:uploadSuccess";
}
return "redirect:uploadFailure";
}
}
----
====
NOTE: When you use Servlet 3.0 multipart parsing, you can also use `javax.servlet.http.Part`,
instead of Spring's `MultipartFile`, as a method argument
Declaring the argument type as a `List<MultipartFile>` allows for resolving multiple
files for the same parameter name.
When the `@RequestParam` annotation is declared as a `Map<String, MultipartFile>` or
`MultiValueMap<String, MultipartFile>`, without a parameter name specified in the annotation,
then the map is populated with the multipart files for each given parameter name.
NOTE: With Servlet 3.0 multipart parsing, you may also declare `javax.servlet.http.Part`
instead of Spring's `MultipartFile`, as a method argument or collection value type.
You can also use multipart content as part of data binding to a
<<mvc-ann-modelattrib-method-args,command object>>. For example, the form field
@ -2604,7 +2613,6 @@ class MyForm {
@@ -2604,7 +2613,6 @@ class MyForm {
private MultipartFile file;
// ...
}
@Controller
@ -2612,16 +2620,13 @@ public class FileUploadController {
@@ -2612,16 +2620,13 @@ public class FileUploadController {
@PostMapping("/form")
public String handleFormUpload(MyForm form, BindingResult errors) {