be resolved * by the DispatcherServlet's ViewResolver
* @see #addObject
*/
public ModelAndView(String viewName) {
this.view = viewName;
}
/**
* Convenient constructor when there is no model data to expose.
* Can also be used in conjunction withaddObject
.
* @param view View object to render
* @see #addObject
*/
public ModelAndView(View view) {
this.view = view;
}
/**
* Creates new ModelAndView given a view name and a model.
* @param viewName name of the View to render, to be resolved
* by the DispatcherServlet's ViewResolver
* @param model Map of model names (Strings) to model objects
* (Objects). Model entries may not benull
, but the
* model Map may be null
if there is no model data.
*/
public ModelAndView(String viewName, Map
model) {
this.view = viewName;
if (model !=null) {
getModelMap().addAllAttributes(model);
}
}
/**
* Creates 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
* @param view View object to render
* @param model Map of model names (Strings) to model objects
* (Objects). Model entries may not benull
, but the
* model Map may be null
if there is no model data.
*/
public ModelAndView(View view, Map
model) {
this.view = view;
if (model !=null) {
getModelMap().addAllAttributes(model);
}
}
/**
* Convenient constructor to take a single model object.
* @param viewName name of the View to render, to be resolved
* by the DispatcherServlet's ViewResolver
* @param modelName name of the single entry in the model
* @param modelObject the single model object
*/
public ModelAndView(String viewName, String modelName, Object modelObject) {
this.view = viewName;
addObject(modelName, modelObject);
}
/**
* Convenient constructor to take a single model object.
* @param view View object to render
* @param modelName name of the single entry in the model
* @param modelObject the single model object
*/
public ModelAndView(View view, String modelName, Object modelObject) {
this.view = view;
addObject(modelName, modelObject);
}
/**
* 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.
*/
publicvoid setViewName(String viewName) {
this.view = viewName;
}
/**
* Return the view name to be resolved by the DispatcherServlet
* via a ViewResolver, or null
if we are using a View object.
*/
public String getViewName() {
return (this.viewinstanceof String (String) this.view :null);
}
/**
* Set a View object for this ModelAndView. Will override any
* pre-existing view name or View.
*/
publicvoid setView(View view) {
this.view = view;
}
/**
* Return the View object, ornull
if we are using a view name
* to be resolved by the DispatcherServlet via a ViewResolver.
*/
public View getView() {
return (this.viewinstanceof View (View) this.view :null);
}
/**
* Indicate whether or not thisModelAndView
has a view, either
* as a view name or as a direct{@link View} instance.
*/
publicboolean hasView() {
return (this.view != null);
}
/**
* Return whether we use a view reference, i.e.true
* if the view has been specified via a name to be resolved by the
* DispatcherServlet via a ViewResolver.
*/
publicboolean isReference() {
return (this.viewinstanceof String);
}
/**
* Return the model map. May returnnull
.
* Called by DispatcherServlet for eva luation of the model.
*/
protected Map
getModelInternal() {
returnthis.model;
}
/**
* Return the underlying ModelMap
instance (neve