Represents a model and view returned by a handler, to be resolved by a DispatcherServlet. The view can take the form of a String view name which will need to be resolved by a ViewResolver object; alternatively a View object can be specified directly. The model is a Map, allowing the use of multiple objects keyed by name.
DispatcherServlet, ViewResolver, HandlerAdapter#handle, org.springframework.web.servlet.mvc.Controller#handleRequest
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private ModelMap | model
Model Map. |
| private HttpStatusCode | status
Optional HTTP status for the response. |
| private Object | view
View instance or view name String. |
| Access | Constructor and Description |
|---|---|
| public | ModelAndView()
Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments. |
| public | ModelAndView(String
name of the View to render, to be resolved
by the DispatcherServlet's ViewResolver viewName)Convenient constructor when there is no model data to expose. |
| public | ModelAndView(View
the View object to render view)Convenient constructor when there is no model data to expose. |
| public | ModelAndView(String
name of the View to render, to be resolved
by the DispatcherServlet's ViewResolver viewName, Map<String, ?> a Map of model names (Strings) to model objects
(Objects). Model entries may not be model)null, but the
model Map may be null if there is no model data.Create a new ModelAndView given a view name and a model. |
| public | ModelAndView(View
the View object to render view, Map<String, ?> a Map of model names (Strings) to model objects
(Objects). Model entries may not be model)null, but the
model Map may be null if there is no model data.Create a new ModelAndView given a View object and a model. |
| public | ModelAndView(String
name of the View to render, to be resolved
by the DispatcherServlet's ViewResolver viewName, HttpStatusCode an HTTP status code to use for the response
(to be set just prior to View rendering) status)Create a new ModelAndView given a view name and HTTP status. |
| public | ModelAndView(String
name of the View to render, to be resolved
by the DispatcherServlet's ViewResolver viewName, Map<String, ?> a Map of model names (Strings) to model objects
(Objects). Model entries may not be model, HttpStatusCode null, but the
model Map may be null if there is no model data.an HTTP status code to use for the response
(to be set just prior to View rendering) status)Create a new ModelAndView given a view name, model, and HTTP status. |
| public | ModelAndView(String
name of the View to render, to be resolved
by the DispatcherServlet's ViewResolver viewName, String name of the single entry in the model modelName, Object the single model object modelObject)Convenient constructor to take a single model object. |
| public | ModelAndView(View
the View object to render view, String name of the single entry in the model modelName, Object the single model object modelObject)Convenient constructor to take a single model object. |
| Modifier and Type | Method and Description |
|---|---|
| public ModelAndView | addAllObjects(Map<String, ?>
a Map of attributeName → attributeValue pairs modelMap)Add all attributes contained in the provided Map to the model. |
| public ModelAndView | |
| public ModelAndView | |
| public void | |
| private String | |
| public Map | |
| protected Map | |
| public ModelMap | |
| public HttpStatusCode | |
| public View | getView()
Return the View object, or |
| public String | getViewName()
Return the view name to be resolved by the DispatcherServlet
via a ViewResolver, or |
| public boolean | |
| public boolean | isEmpty()
Return whether this ModelAndView object is empty, i.e. whether it does not hold any view and does not contain a model. |
| public boolean | isReference()
Return whether we use a view reference, i.e. |
| public void | |
| public void | |
| public void | setViewName(String viewName)
Set a view name for this ModelAndView, to be resolved by the DispatcherServlet via a ViewResolver. |
| public String | toString()
Overrides java. Return diagnostic information about this model and view. |
| public boolean | wasCleared()
Return whether this ModelAndView object is empty as a result of a call to |
| cleared | back to summary |
|---|---|
| private boolean cleared Indicates whether this instance has been cleared with a call to | |
| model | back to summary |
|---|---|
| private ModelMap model Model Map. | |
| status | back to summary |
|---|---|
| private HttpStatusCode status Optional HTTP status for the response. | |
| view | back to summary |
|---|---|
| private Object view View instance or view name String. | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView() Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.
| |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(String viewName) Convenient constructor when there is no model data to expose.
Can also be used in conjunction with | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(View view) Convenient constructor when there is no model data to expose.
Can also be used in conjunction with | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(String viewName, Map<String, ?> model) Create a new ModelAndView given a view name and a model. | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(View view, Map<String, ?> model) Create a new ModelAndView given a View object and a model. Note the supplied model data is copied into the internal storage of this class. You should not consider to modify the supplied Map after supplying it to this class | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(String viewName, HttpStatusCode status) Create a new ModelAndView given a view name and HTTP status.
| |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(String viewName, Map<String, ?> model, HttpStatusCode status) Create a new ModelAndView given a view name, model, and HTTP status.
| |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(String viewName, String modelName, Object modelObject) Convenient constructor to take a single model object. | |
| ModelAndView | back to summary |
|---|---|
| public ModelAndView(View view, String modelName, Object modelObject) Convenient constructor to take a single model object. | |
| addAllObjects | back to summary |
|---|---|
| public ModelAndView addAllObjects(Map<String, ?> modelMap) Add all attributes contained in the provided Map to the model.
| |
| addObject | back to summary |
|---|---|
| public ModelAndView addObject(String attributeName, Object attributeValue) Add an attribute to the model.
| |
| addObject | back to summary |
|---|---|
| public ModelAndView addObject(Object attributeValue) Add an attribute to the model using parameter name generation.
| |
| clear | back to summary |
|---|---|
| public void clear() Clear the state of this ModelAndView object. The object will be empty afterwards. Can be used to suppress rendering of a given ModelAndView object
in the
| |
| formatView | back to summary |
|---|---|
| private String formatView() | |
| getModel | back to summary |
|---|---|
| public Map Return the model map. Never returns | |
| getModelInternal | back to summary |
|---|---|
| protected Map Return the model map. May return
| |
| getModelMap | back to summary |
|---|---|
| public ModelMap getModelMap() Return the underlying | |
| getStatus | back to summary |
|---|---|
| public HttpStatusCode getStatus() Return the configured HTTP status for the response, if any.
| |
| getView | back to summary |
|---|---|
| public View getView() Return the View object, or
| |
| getViewName | back to summary |
|---|---|
| public String getViewName() Return the view name to be resolved by the DispatcherServlet
via a ViewResolver, or
| |
| hasView | back to summary |
|---|---|
| public boolean hasView() Indicate whether this | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Return whether this ModelAndView object is empty, i.e. whether it does not hold any view and does not contain a model. | |
| isReference | back to summary |
|---|---|
| public boolean isReference() Return whether we use a view reference, i.e. | |
| setStatus | back to summary |
|---|---|
| public void setStatus(HttpStatusCode status) Set the HTTP status to use for the response. The response status is set just prior to View rendering.
| |
| setView | back to summary |
|---|---|
| public void setView(View view) Set a View object for this ModelAndView. Will override any pre-existing view name or View. | |
| setViewName | back to summary |
|---|---|
| public void setViewName(String viewName) Set a view name for this ModelAndView, to be resolved by the DispatcherServlet via a ViewResolver. Will override any pre-existing view name or View. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Return diagnostic information about this model and view.
| |
| wasCleared | back to summary |
|---|---|
| public boolean wasCleared() Return whether this ModelAndView object is empty as a result of a call to Returns
| |