I know in spring mvc in @Controller class in @RequestMapping method I can return
I don\'t understa
Unless your return type is void
or you annotate your method with @ResponseBody
, Spring MVC will try to resolve a View
to render the response.
Therefore, you must somehow point the framework to a View
instance or to the name of a view as String
in your returned value (or rely on the implicit resolving and perhaps only return the Model
); if you return a name (either as a mere String
or embedded in a ModelAndView
), that will then be passed to a configured ViewResolver
to obtain an actual View
instance.
The ModelAndView
container does hold a reference to a View
or view name and also embeds the model to use.
In Spring 3.2.x there are more then just those 3. See the docs at the Spring website. Latests Spring (4.2.x) documentation.
The following are the supported return types:
@ModelAttribute
annotated reference data accessor methods.@ModelAttribute
annotated reference data accessor methods.@ModelAttribute
annotated reference data accessor methods.@ModelAttribute
annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above).@ModelAttribute
annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above).@ResponseBody
annotation”.@ModelAttribute
at the method level (or the default attribute name based on the return type class name). The model is implicitly enriched with command objects and the results of @ModelAttribute
annotated reference data accessor methods.Everything is in the documentation: http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-return-types