java - Which return type use in spring mvc in @RequestMapping method? -


i know in spring mvc in @controller class in @requestmapping method can return

  1. string
  2. model
  3. modelandview

i don't understand differencies between these actions. can explain me it?

in spring 3.2.x there more 3. see docs @ spring website. latests spring (4.2.x) documentation.

the following supported return types:

  • a modelandview object, model implicitly enriched command objects , results of @modelattribute annotated reference data accessor methods.
  • a model object, view name implicitly determined through requesttoviewnametranslator , model implicitly enriched command objects , results of @modelattribute annotated reference data accessor methods.
  • a map object exposing model, view name implicitly determined through requesttoviewnametranslator , model implicitly enriched command objects , results of @modelattribute annotated reference data accessor methods.
  • a view object, model implicitly determined through command objects , @modelattribute annotated reference data accessor methods. handler method may programmatically enrich model declaring model argument (see above).
  • a string value interpreted logical view name, model implicitly determined through command objects , @modelattribute annotated reference data accessor methods. handler method may programmatically enrich model declaring model argument (see above).
  • void if method handles response (by writing response content directly, declaring argument of type servletresponse / httpservletresponse purpose) or if view name supposed implicitly determined through requesttoviewnametranslator (not declaring response argument in handler method signature).
  • if method annotated @responsebody, return type written response http body. return value converted declared method argument type using httpmessageconverters. see section called “mapping response body @responsebody annotation”.
  • a httpentity** or **responseentity object provide access servlet response http headers , contents. entity body converted response stream using httpmessageconverters. see section called “using httpentity”.
  • a callable can returned when application wants produce return value asynchronously in thread managed spring mvc.
  • a deferredresult can returned when application wants produce return value thread of own choosing.
  • any other return type considered single model attribute exposed view, using attribute name specified through @modelattribute @ method level (or default attribute name based on return type class name). model implicitly enriched command objects , results of @modelattribute annotated reference data accessor methods.

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -