类 ModelAndView
- java.lang.Object
- org.springframework.web.portlet.ModelAndView
public class ModelAndView extends Object
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 DispatcherPortlet. 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.
- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
DispatcherPortlet,ViewResolver,HandlerAdapter,Controller
构造器概要
构造器 构造器 说明 ModelAndView()Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.ModelAndView(Object view)Convenient constructor when there is no model data to expose.ModelAndView(Object view, String modelName, Object modelObject)Convenient constructor to take a single model object.ModelAndView(Object 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, 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.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ModelAndViewaddAllObjects(Map<String,?> modelMap)Add all attributes contained in the provided Map to the model.ModelAndViewaddObject(Object attributeValue)Add an attribute to the model using parameter name generation.ModelAndViewaddObject(String attributeName, Object attributeValue)Add an attribute to the model.voidclear()Clear the state of this ModelAndView object.Map<String,Object>getModel()Return the model map.protected Map<String,Object>getModelInternal()Return the model map.ModelMapgetModelMap()Return the underlyingModelMapinstance (nevernull).ObjectgetView()Return the View object, ornullif we are using a view name to be resolved by the DispatcherPortlet via a ViewResolver.StringgetViewName()Return the view name to be resolved by the DispatcherPortlet 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 direct view instance.booleanisEmpty()Return whether this ModelAndView object is empty, i.e. whether it does not hold any view and does not contain a model.booleanisReference()Return whether we use a view reference, i.e.voidsetView(Object view)Set a View object for this ModelAndView.voidsetViewName(String viewName)Set a view name for this ModelAndView, to be resolved by the DispatcherPortlet via a ViewResolver.StringtoString()Return diagnostic information about this model and view.booleanwasCleared()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.
构造器详细资料
ModelAndView
public ModelAndView()
Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.
ModelAndView
public ModelAndView(String viewName)
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 DispatcherPortlet's ViewResolver- 另请参阅:
addObject(java.lang.String, java.lang.Object)
ModelAndView
public ModelAndView(Object view)
Convenient constructor when there is no model data to expose. Can also be used in conjunction withaddObject.- 参数:
view- View object to render (usually a Servlet MVC View object)- 另请参阅:
addObject(java.lang.String, java.lang.Object)
ModelAndView
public ModelAndView(String viewName, Map<String,?> model)
Create a new ModelAndView given a view name and a model.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherPortlet's ViewResolvermodel- 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
public ModelAndView(Object view, Map<String,?> model)
Create a new ModelAndView given a View object and a model.- 参数:
view- View object to render (usually a Servlet MVC View object)model- 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
public ModelAndView(String viewName, String modelName, Object modelObject)
Convenient constructor to take a single model object.- 参数:
viewName- name of the View to render, to be resolved by the DispatcherPortlet's ViewResolvermodelName- name of the single entry in the modelmodelObject- the single model object
ModelAndView
public ModelAndView(Object view, String modelName, Object modelObject)
Convenient constructor to take a single model object.- 参数:
view- View object to render (usually a Servlet MVC View object)modelName- name of the single entry in the modelmodelObject- the single model object
方法详细资料
setViewName
public void setViewName(String viewName)
Set a view name for this ModelAndView, to be resolved by the DispatcherPortlet via a ViewResolver. Will override any pre-existing view name or View.
getViewName
public String getViewName()
Return the view name to be resolved by the DispatcherPortlet via a ViewResolver, ornullif we are using a view object.
setView
public void setView(Object view)
Set a View object for this ModelAndView. Will override any pre-existing view name or View.The given View object will usually be a Servlet MVC View object. This is nevertheless typed as Object to avoid a Servlet API dependency in the Portlet ModelAndView class.
getView
public Object getView()
Return the View object, ornullif we are using a view name to be resolved by the DispatcherPortlet via a ViewResolver.
hasView
public boolean hasView()
Indicate whether or not thisModelAndViewhas a view, either as a view name or as a direct view instance.
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 DispatcherPortlet via a ViewResolver.
getModelInternal
protected Map<String,Object> getModelInternal()
Return the model map. May returnnull. Called by DispatcherPortlet for evaluation of the model.
getModelMap
public ModelMap getModelMap()
Return the underlyingModelMapinstance (nevernull).
getModel
public Map<String,Object> getModel()
Return the model map. Never returnsnull. To be called by application code for modifying the model.
addObject
public ModelAndView addObject(String attributeName, Object attributeValue)
Add an attribute to the model.- 参数:
attributeName- name of the object to add to the modelattributeValue- object to add to the model (nevernull)- 另请参阅:
ModelMap.addAttribute(String, Object),getModelMap()
addObject
public ModelAndView addObject(Object attributeValue)
Add an attribute to the model using parameter name generation.- 参数:
attributeValue- the object to add to the model (nevernull)- 另请参阅:
ModelMap.addAttribute(Object),getModelMap()
addAllObjects
public ModelAndView addAllObjects(Map<String,?> modelMap)
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
postHandleRendermethod 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. Returnsfalseif any additional state was added to the instance after the call toclear().- 另请参阅:
clear()