SPRINGMVC Modelandview function and function analysis "turn"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.