@@ -2622,33 +2622,41 @@ query parameters and form fields. The following example shows how to do so:
2622
2622
.Java
2623
2623
----
2624
2624
@PostMapping("/owners/{ownerId}/pets/{petId}/edit")
2625
- public String processSubmit(@ModelAttribute Pet pet) { } <1>
2625
+ public String processSubmit(@ModelAttribute Pet pet) {
2626
+ // method logic...
2627
+ }
2626
2628
----
2627
- <1> Bind an instance of `Pet`.
2628
2629
2629
2630
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
2630
2631
.Kotlin
2631
2632
----
2632
2633
@PostMapping("/owners/{ownerId}/pets/{petId}/edit")
2633
- fun processSubmit(@ModelAttribute pet: Pet): String { } // <1>
2634
+ fun processSubmit(@ModelAttribute pet: Pet): String {
2635
+ // method logic...
2636
+ }
2634
2637
----
2635
- <1> Bind an instance of `Pet`.
2636
-
2637
- The `Pet` instance above is resolved as follows:
2638
-
2639
- * From the model if already added by using <<mvc-ann-modelattrib-methods>>.
2640
- * From the HTTP session by using <<mvc-ann-sessionattributes>>.
2641
- * From a URI path variable passed through a `Converter` (see the next example).
2642
- * From the invocation of a default constructor.
2643
- * From the invocation of a "`primary constructor`" with arguments that match to Servlet
2644
- request parameters. Argument names are determined through JavaBeans
2645
- `@ConstructorProperties` or through runtime-retained parameter names in the bytecode.
2646
2638
2647
- While it is common to use a <<mvc-ann-modelattrib-methods>> to populate the model with
2648
- attributes, one other alternative is to rely on a `Converter<String, T>` in combination
2649
- with a URI path variable convention. In the following example, the model attribute name,
2650
- `account`, matches the URI path variable, `account`, and the `Account` is loaded by passing
2651
- the `String` account number through a registered `Converter<String, Account>`:
2639
+ The `Pet` instance above is sourced in one of the following ways:
2640
+
2641
+ * Retrieved from the model where it may have been added by a
2642
+ <<mvc-ann-modelattrib-methods,@ModelAttribute method>>.
2643
+ * Retrieved from the HTTP session if the model attribute was listed in
2644
+ the class-level <<mvc-ann-sessionattributes>> annotation.
2645
+ * Obtained through a `Converter` where the model attribute name matches the name of a
2646
+ request value such as a path variable or a request parameter (see next example).
2647
+ * Instantiated using its default constructor.
2648
+ * Instantiated through a "`primary constructor`" with arguments that match to Servlet
2649
+ request parameters. Argument names are determined through JavaBeans
2650
+ `@ConstructorProperties` or through runtime-retained parameter names in the bytecode.
2651
+
2652
+ One alternative to using a <<mvc-ann-modelattrib-methods,@ModelAttribute method>> to
2653
+ supply it or relying on the framework to create the model attribute, is to have a
2654
+ `Converter<String, T>` to provide the instance. This is applied when the model attribute
2655
+ name matches to the name of a request value such as a path variable or a request
2656
+ parameter, and there is a `Converter` from `String` to the model attribute type.
2657
+ In the following example, the model attribute name is `account` which matches the URI
2658
+ path variable `account`, and there is a registered `Converter<String, Account>` which
2659
+ could load the `Account` from a data store:
2652
2660
2653
2661
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
2654
2662
.Java
0 commit comments