7.SpringMVC Profile Development-modelandview and view resolver

Source: Internet
Author: User


1.Model (model)

The essence of 1.model is hashmap, adding data to the model, that is, adding data to the HashMap.

2.HashMap is a one-way lookup array, one-way linked list array

3.LinkedHashMap, essentially a hashmap, but it expands the entry and turns it into a two-way

2.View (view)

Modelandview internally by Setviewname () to specify the view name

This view name corresponds to a View object, which is encapsulated in Modelandview and passed to the view parser to parse

View Resolver Viewresolver

Attempting to parse the Viewresolver interface is responsible for generating the view view of the processing results, there are four common implementation classes

(1) Internalresourceviewresolver view parser (default)

This view resolver is used to encapsulate and jump through the internal resources of the current web app (you can choose whether to stitch Web resource names)

For internal resource definitions, you can define only one format resource: A resource file of the same file type that resides in the same directory

(2) Beannameviewreolver View parser (can be turned to external resources)

Multiple view-view beans can be defined, allowing Modelandview in the processor to pass a reference to the ID of these beans to complete the jump to the encapsulated resource in the view

1 <Beanclass= "Org.springframework.web.servlet.view.BeanNameViewResolver"/>2     3     <!--define multiple View-view beans to allow Modelandview in the processor to complete a jump to the encapsulated resource in View by referencing the Bean's ID -4     <!--define an external resource View object -5     <BeanID= "Taobao"class= "Org.springframework.web.servlet.view.RedirectView">6         < Propertyname= "url"value= "Http://www.taobao.com"/>7     </Bean>8     9     <!--define an external resource View object -Ten     <BeanID= "Baidu"class= "Org.springframework.web.servlet.view.RedirectView"> One         < Propertyname= "url"value= "Http://www.baidu.com"/> A     </Bean> -      -     <!--define an internal resource View object - the     <BeanID= "Myinternalview"class= "Org.springframework.web.servlet.view.JstlView"> -         < Propertyname= "url"value= "/web-inf/jsp/hello.jsp"/> -     </Bean> -  +  -     <BeanID= "/hello.do"class= "Com.springmvc.handlers.MyController"/> +      A      at  - </Beans>

3.XmlViewResolver View Parser and Resourcebundleviewresolver view parser

When you need to define a lot of view objects, you make the Springmvc.xml file large,

So you can extract these view objects specifically to define an XML or resource file for unified management

The priority of the view parser

The view parser has an order property that is designed to prioritize multiple view parsers. The smaller the number, the higher the priority, the same number, the higher priority for registering first


1 <Beanclass= "Org.springframework.web.servlet.view.XmlViewResolver">2         < Propertyname= "Location"value= "Classpath:myViews.xml"></ Property>3         < Propertyname= "Order"value= "1"></ Property>4     </Bean>

7.SpringMVC Profile Development-modelandview and view resolver

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.