Spring MVC View mechanism
All of the MVC frameworks for Web applications have a way to locate views. Spring provides a view parser for you to display model data in a browser, without having to be constrained to specific view technologies.
The director controller of Spring returns an instance of Modelandview. Spring feeds information to the user based on the view and model in the Modelandview instance . The view in spring is identified by name, andViewresolver is parsed by name . Spring provides a variety of views and view parsers.
A ,Modelandview
Org.springframework.web.servlet.ModelAndView
public class Modelandview extends Object
Modelandview as its name implies, it represents the model and View used in Spring Web MVC to render the screen , since Java can only return one object at a time, so The Modelandview function encapsulates these two objects to allow you to return both the model and view objects at once.
Construction method
Modelandview (String viewName)
Convenient constructor when there are no model data to expose.
The simplest Modelandview is only the name of the view , and then the view name is the View resolver, which is Org.springframework.web.servlet.View instance parsing, such as Internalresourceview or Jstlview, and so on.
Modelandview (String viewName, Map model)
Creates new Modelandview given a view name and a model.
If you want to return the model data you need to render the screen , you can use map to collect the data that is needed to render the view, and then construct the Modelandview as a construct parameter.
Modelandview (String viewName, String modelname, Object modelobject)
Convenient constructor to take a single model object.
Used when returning a single model.
B ,viewresolver (view resolver)
Org.springframework.web.servlet.ViewResolver
public interface Viewresolver
Now that we have the view name and the model material we need to display it , how do we show the view? This requires the use of Viewresolver, which provides a mapping from the view name to the actual view.
(for example, the view name we get is called test, by viewresolver we map it to /web-inf/jsp/test.jsp's resources, and of course we can map test to Test.pdf resources, this part of the work is done by Viewresolver, but specifically how to display test.jsp or test.pdf, you need view to achieve).
SPRINGMVC Modelandview function and function analysis "turn"