diff --git a/spring-framework-reference/src/mvc.xml b/spring-framework-reference/src/mvc.xml
index 6611c231ba0..5829584dc00 100644
--- a/spring-framework-reference/src/mvc.xml
+++ b/spring-framework-reference/src/mvc.xml
@@ -603,23 +603,22 @@
public class HelloWorldController {
@RequestMapping("/helloWorld")
- public ModelAndView helloWorld() {
- ModelAndView mav = new ModelAndView();
- mav.setViewName("helloWorld");
- mav.addObject("message", "Hello World!");
- return mav;
+ public String helloWorld(Model model) {
+ model.addAttribute("message", "Hello World!");
+ return "helloWorld";
}
}
As you can see, the @Controller and
@RequestMapping annotations allow flexible
- method names and signatures. In this particular example the method has no
- parameters and returns a ModelAndView, but various
- other (and better) strategies exist, as
- are explained later in this section. ModelAndView,
- @Controller, and
- @RequestMapping form the basis for the
- Spring MVC implementation. This section documents these annotations and
+ method names and signatures. In this particular example the method accepts
+ a Model and returns a view name as a
+ String, but various other method parameters and
+ return values can be used as explained later in this section.
+ @Controller and
+ @RequestMapping and a number of other
+ annotations form the basis for the Spring MVC implementation.
+ This section documents these annotations and
how they are most commonly used in a Servlet environment.
@@ -679,7 +678,7 @@ public class HelloWorldController {
class-level annotation maps a specific request path (or path pattern)
onto a form controller, with additional method-level annotations
narrowing the primary mapping for a specific HTTP method request method
- ("GET"/"POST") or specific HTTP request parameters.
+ ("GET", "POST", etc.) or an HTTP request parameter condition.
The following example shows a controller in a Spring MVC
application that uses this annotation:
@@ -894,8 +893,8 @@ public class RelativePathUriTemplateController {
Date, etc. Spring automatically converts to the appropriate type and
throws a TypeMismatchException if the type is
not correct. You can further customize this conversion process by
- customizing the data binder. See .
+ customizing the data binder. See
+ and .
@@ -1252,6 +1251,10 @@ public class EditPetForm {
required attribute to false
(e.g., @RequestParam(value="id",
required=false)).
+
+ Type conversion is applied automatically if the target method parameter
+ type is not String.
+ See .
@@ -1516,6 +1519,10 @@ public void displayHeaderInfo(@CookieValue("JSESSIONID")
}
+ Type conversion is applied automatically if the target method
+ parameter type is not String.
+ See .
+
This annotation is supported for annotated handler methods in
Servlet and Portlet environments.
@@ -1550,10 +1557,40 @@ public void displayHeaderInfo(@RequestHeader("Accept-Encod
}
+ Type conversion is applied automatically if the method parameter
+ is not String.
+ See .
+
+ Built-in support is available for converting a coma-separated
+ string into an array/collection of strings or other types known to the
+ type conversion system. For example a method parameter annotated with
+ @RequestHeader("Accept") may be of type
+ String but also String[]
+ or List<String>.
+
This annotation is supported for annotated handler methods in
Servlet and Portlet environments.
+
+ Method Parameters And Type Conversion
+
+ String-based values extracted from the request including
+ request parameters, path variables, request headers, and cookie values
+ may need to be converted to the target type of the method parameter or
+ field (e.g. binding a request parameter to a field in an
+ @ModelAttribute parameter) they're bound to.
+ If the target type is not String, Spring
+ automatically converts to the appropriate type.
+ All simple types such as int, long, Date, etc. are
+ supported. You can further customize the conversion process
+ through a WebDataBinder
+ (see ) or by registering
+ Formatters with the
+ FormattingConversionService
+ (see ).
+
+
Customizing WebDataBinder
initialization