类 ModelAndView
java.lang.Object
cn.taketoday.web.view.ModelAndView
Holder for both Model and View in the web MVC framework.
Note that these are entirely distinct. This class merely holds
both to make it possible for a controller to return both model
and view in a single return value.
Represents a model and view returned by a handler, to be resolved by a ReturnValueHandler. 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.
- 从以下版本开始:
- 2018-12-02 19:54
- 作者:
- Rod Johnson, Juergen Hoeller, Rob Harrop, Rossen Stoyanchev, TODAY
-
字段概要
字段 -
构造器概要
构造器构造器说明Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.ModelAndView(View view) Convenient constructor when there is no model data to expose.ModelAndView(View view, String modelName, Object modelObject) Convenient constructor to take a single model object.ModelAndView(View view, Map<String, ?> model) Create a new ModelAndView given a View object and a model.ModelAndView(String viewName) Convenient constructor when there is no model data to expose.ModelAndView(String viewName, HttpStatusCode status) Create a new ModelAndView given a view name and HTTP status.ModelAndView(String viewName, String modelName, Object modelObject) Convenient constructor to take a single model object.ModelAndView(String viewName, Map<String, ?> model) Create a new ModelAndView given a view name and a model.ModelAndView(String viewName, Map<String, ?> model, HttpStatusCode status) Create a new ModelAndView given a view name, model, and HTTP status. -
方法概要
修饰符和类型方法说明addAllObjects(Map<String, ?> modelMap) Add all attributes contained in the provided Map to the model.Add an attribute to the model using parameter name generation.Add an attribute to the model.voidclear()Clear the state of this ModelAndView object.private StringgetModel()Return the model map.cn.taketoday.ui.ModelMapReturn the underlyingModelMapinstance (nevernull).Return the configured HTTP status for the response, if any.getView()Return the View object, ornullif we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.Return the view name to be resolved by the DispatcherServlet via a ViewResolver, ornullif we are using a View object.booleanhasView()Indicate whether or not thisModelAndViewhas a view, either as a view name or as a directViewinstance.booleanisEmpty()Return whether this ModelAndView object is empty, i.e. whether it does not hold any view and does not contain a model.booleanReturn whether we use a view reference, i.e.voidsetStatus(HttpStatusCode status) Set the HTTP status to use for the response.voidSet a View object for this ModelAndView.voidsetViewName(String viewName) Set a view name for this ModelAndView, to be resolved by the DispatcherServlet via a ViewResolver.toString()Return diagnostic information about this model and view.booleanReturn whether this ModelAndView object is empty as a result of a call toclear()i.e. whether it does not hold any view and does not contain a model.
-
字段详细资料
-
view
View instance or view name String. -
model
@Nullable private cn.taketoday.ui.ModelMap modelModel Map. -
status
Optional HTTP status for the response. -
cleared
private boolean clearedIndicates whether or not this instance has been cleared with a call toclear().
-
-
构造器详细资料
-
ModelAndView
public ModelAndView()Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments. -
ModelAndView
Convenient constructor when there is no model data to expose. Can also be used in conjunction withaddObject.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherServlet's ViewResolver- 另请参阅:
-
ModelAndView
Convenient constructor when there is no model data to expose. Can also be used in conjunction withaddObject.- 参数:
view- the View object to render- 另请参阅:
-
ModelAndView
Create a new ModelAndView given a view name and a model.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherServlet's ViewResolvermodel- a Map of model names (Strings) to model objects (Objects). Model entries may not benull, but the model Map may benullif there is no model data.
-
ModelAndView
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- 参数:
view- the View object to rendermodel- a Map of model names (Strings) to model objects (Objects). Model entries may not benull, but the model Map may benullif there is no model data.
-
ModelAndView
Create a new ModelAndView given a view name and HTTP status.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherServlet's ViewResolverstatus- an HTTP status code to use for the response (to be set just prior to View rendering)
-
ModelAndView
public ModelAndView(@Nullable String viewName, @Nullable Map<String, ?> model, @Nullable HttpStatusCode status) Create a new ModelAndView given a view name, model, and HTTP status.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherServlet's ViewResolvermodel- a Map of model names (Strings) to model objects (Objects). Model entries may not benull, but the model Map may benullif there is no model data.status- an HTTP status code to use for the response (to be set just prior to View rendering)
-
ModelAndView
Convenient constructor to take a single model object.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherServlet's ViewResolvermodelName- name of the single entry in the modelmodelObject- the single model object
-
ModelAndView
Convenient constructor to take a single model object.- 参数:
view- the View object to rendermodelName- name of the single entry in the modelmodelObject- the single model object
-
-
方法详细资料
-
setViewName
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. -
getViewName
Return the view name to be resolved by the DispatcherServlet via a ViewResolver, ornullif we are using a View object. -
setView
Set a View object for this ModelAndView. Will override any pre-existing view name or View. -
getView
Return the View object, ornullif we are using a view name to be resolved by the DispatcherServlet via a ViewResolver. -
hasView
public boolean hasView()Indicate whether or not thisModelAndViewhas a view, either as a view name or as a directViewinstance. -
isReference
public boolean isReference()Return whether we use a view reference, i.e.trueif the view has been specified via a name to be resolved by the DispatcherServlet via a ViewResolver. -
getModelMap
public cn.taketoday.ui.ModelMap getModelMap()Return the underlyingModelMapinstance (nevernull). -
getModel
Return the model map. Never returnsnull. To be called by application code for modifying the model. -
setStatus
Set the HTTP status to use for the response.The response status is set just prior to View rendering.
-
getStatus
Return the configured HTTP status for the response, if any. -
addObject
Add an attribute to the model.- 参数:
attributeName- name of the object to add to the model (nevernull)attributeValue- object to add to the model (can benull)- 另请参阅:
-
ModelMap.addAttribute(String, Object)getModelMap()
-
addObject
Add an attribute to the model using parameter name generation.- 参数:
attributeValue- the object to add to the model (nevernull)- 另请参阅:
-
ModelMap.addAttribute(Object)getModelMap()
-
addAllObjects
Add all attributes contained in the provided Map to the model.- 参数:
modelMap- a Map of attributeName → attributeValue pairs- 另请参阅:
-
ModelMap.addAllAttributes(Map)getModelMap()
-
clear
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
postHandlemethod of a HandlerInterceptor. -
isEmpty
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. -
wasCleared
public boolean wasCleared()Return whether this ModelAndView object is empty as a result of a call toclear()i.e. whether it does not hold any view and does not contain a model.Returns
falseif any additional state was added to the instance after the call toclear().- 另请参阅:
-
toString
Return diagnostic information about this model and view. -
formatView
-