Getting Started 19 - ModelandView Categories
The ModelAndView category is as indicated by its name, which represents the object of Model and View in the MVC web program, but it just makes it easy for you to return these two objects. The simplest ModelandView is the name that holds the View, then the View Resolver is VIEW RESOLVER, which is an instance parsing of the Org.SpringFramework.Web.Servlet.View interface, such as internalResourceView or JstlView, etc .:
ModelandView (String ViewName)
If you want to return Model objects, you can use Map to collect these model objects, then set to ModlandView, use the following version of ModelandView:
ModelandView (String ViewName, Map Model)
Set the key and value value in the map object, you can take it in the view, if you just want to return a Model object, you can use the ModelandView version:
ModelandView (String ViewName, String Modelname, Object Modelobject)
With ModelName, you can remove the model and display in the view. The ModelandView category provides objects for the VIEW interface to make the parameters for View:
ModelandView (View View)
ModelandView (View View, Map Model)
ModilandView (View View, String Modelname, Object Modelobject)
An example is org.SpringFramework.web.Servlet.View.RedirectView, ModelandView preset is to forward request results to a view, use RedirectView, use Redirect to view the request, for example::
...
Public ModlandView HandleRequest (....) ... {
....
Return New ModelandView (this.getViewPage ()));
}
....
Here, the address of the ViewPage is specified from the server web root directory, not the root directory of the web application, so your getViewPage () The address returned to the address like /springapp/pages/index.htm, SpringApp is your web application directory. With Forward, the URL column does not appear forwarded destination address, and forward is in the web application, you can access the hidden directory of the web application, like web-inf, but Forward can only be available in web applications The program is performed and cannot be specified to other web application addresses. When using redirect, it is required to request a client browser to re-issue a specified request address, so the reusable directory address will appear on the URL column, and the recipient request is issued by the browser, so you cannot access hidden in the web application. Directory, like web-inf, but re-relocate is a web page, so you can specify to other web application addresses. DispatcherServlets will resolve the VIEW name according to the back ModelandView and process the model given. The VIEW name is the instance of the entrustment to org.springframework.web.Servlet.ViewResolver interface, the ViewResolver interface is defined as follows: public interface viewresolver {
Public View ResolveViewName (String, Locale Locale) Throws servletexception;
}
An instance of ViewResolver is the initialResourceViewResolver. After the name is parsed, the actual View drawroom is given to the instance of the actual org.springframework.web.servlet.view, the View interface is as follows:
Public interface view {
Public Void Render (Map Model, HttpservletResquest Resquest, HttpservletResponse Response) Throws ServleTexception, IOException
}
The actual actuatus of View is used org.springframework.web.servlet.view.internalResourceView, and there are also practicals such as JstlView, TilesView, VelocityView, etc., respectively.