Spring MVC Fundamentals Article 6

Source: Internet
Author: User

Spring MVC View Parser

1. Request direct access to the page without controller

<!---<path= "/success"  view-name = "Success" /> <!--  -<mvc:annotation-driven></MVC: Annotation-driven>

2. Accessing the page static resources

<!--configure access to static resources start -<mvc:resourcesMapping= "/js/**" Location= "/resources/js/" /><mvc:resourcesMapping= "/css/**" Location= "/resources/css/" /><mvc:resourcesMapping= "/images/**" Location= "/resources/images/" /><mvc:resourcesMapping= "/upload/**" Location= "/upload/" /><mvc:resourcesMapping= "/**/*.html" Location="/"/><!--<mvc:default-servlet-handler/> -<Mvc:annotation-driven></Mvc:annotation-driven><!--configure access to static resources end -

3. Custom views

/*** 1. Customize the view to implement the view interface, override the method for the, and then add the custom view to the spring IOC container in * 2.Controller to return the custom view in the Spring container name * 3. The remaining operations are implemented by render and getContentType **/@Component Public classSelfviewImplementsview{ PublicString getContentType () {return"Text/html"; }     Public voidRender (Map<string,?>model, HttpServletRequest request, httpservletresponse response)throwsException {response.getwriter (). Print ("Hello View, Time:" +NewDate ()); }}
    @RequestMapping ("TestView")    public  String TestView () {        System.out.println (" Hello This is TestView ");         return "Selfview";    }    
    <!--Configure the View resolver: How to resolve the handler method return value to the actual physical view -    <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">        < Propertyname= "prefix"value= "/web-inf/views/"></ Property>        < Propertyname= "suffix"value= ". jsp"></ Property>    </Bean>    <!--Configure the View resolver for the Beanname order to give the view priority a random value for the row is lower than the Internalresourceviewresolver priority level -    <Beanclass= "Org.springframework.web.servlet.view.BeanNameViewResolver">         < Propertyname= "Order"value= "+"></ Property>    </Bean>

Spring MVC Fundamentals Article 6

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.