Skip to content

Commit daba9e5

Browse files
committed
Merge branch '6.1.x'
2 parents 717b972 + 83be0f2 commit daba9e5

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Kotlin::
3434
You can use the xref:web/webmvc/mvc-config/message-converters.adoc[Message Converters] option of the xref:web/webmvc/mvc-config.adoc[MVC Config] to
3535
configure or customize message conversion.
3636

37+
NOTE: Form data should be read using xref:web/webmvc/mvc-controller/ann-methods/requestparam.adoc[`@RequestParam`],
38+
not with `@RequestBody` which can't always be used reliably since in the Servlet API, request parameter
39+
access causes the request body to be parsed, and it can't be read again.
40+
3741
You can use `@RequestBody` in combination with `jakarta.validation.Valid` or Spring's
3842
`@Validated` annotation, both of which cause Standard Bean Validation to be applied.
3943
By default, validation errors cause a `MethodArgumentNotValidException`, which is turned

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

+42
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,48 @@ values for the same parameter name.
7272
When an `@RequestParam` annotation is declared as a `Map<String, String>` or
7373
`MultiValueMap<String, String>`, without a parameter name specified in the annotation,
7474
then the map is populated with the request parameter values for each given parameter name.
75+
The following example shows how to do so with form data processing:
76+
77+
[tabs]
78+
======
79+
Java::
80+
+
81+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
82+
----
83+
@Controller
84+
@RequestMapping("/pets")
85+
class EditPetForm {
86+
87+
// ...
88+
89+
@PostMapping(value = "/process", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
90+
public String processForm(@RequestParam MultiValueMap<String, String> params) {
91+
// ...
92+
}
93+
94+
// ...
95+
}
96+
----
97+
Kotlin::
98+
+
99+
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
100+
----
101+
@Controller
102+
@RequestMapping("/pets")
103+
class EditPetForm {
104+
105+
// ...
106+
107+
@PostMapping("/process", consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
108+
fun processForm(@RequestParam params: MultiValueMap<String, String>): String {
109+
// ...
110+
}
111+
112+
// ...
113+
114+
}
115+
----
116+
======
75117

76118
Note that use of `@RequestParam` is optional (for example, to set its attributes).
77119
By default, any argument that is a simple value type (as determined by

0 commit comments

Comments
 (0)