SPRINGMVC Study Summary (iii)--controller interface detailed (1)

Source: Internet
Author: User

4.12, Parameterizableviewcontroller

Parameterized view controller, without functional processing (i.e. static view), directly selects the view to be displayed based on the logical view name of the parameter.

<bean name= "/parameterizableview"     class= " Org.springframework.web.servlet.mvc.ParameterizableViewController ">     <property name=" ViewName "value=" Success "/>     </bean>

The controller directly selects the parameterized view after receiving the request, the benefit is to configure in the configuration file, so as to avoid the hard coding of the program, such as the help page and so on do not need to do the function processing, so directly use the controller map to the view.

4.13, Abstracturlviewcontroller

Provides a supported base class that translates directly to a logical view name based on the request URL path, i.e. no function processing is required, the logical view name is computed directly from the URL and the specific view is selected for presentation:

UrlDecode : If URL decoding is not specified, the default is to decode using server encoding (such as Tomcat default iso-8859-1);

Urlpathhelper : the tool class used to parse the request path, which defaults to Org.springframework.web.util.UrlPathHelper.

Urlfilenameviewcontroller is one of its implementations, so we should use Urlfilenameviewcontroller.

4.14, Urlfilenameviewcontroller

Convert the requested URL path to the logical view name and return the conversion controller, i.e. no function processing is required, the logical view name is computed directly from the URL and the specific view is selected for presentation:

Calculates the logical view name based on the request URL path;

<bean name= "/index1/*"      class= "Org.springframework.web.servlet.mvc.UrlFilenameViewController"/>     <bean name= "/index2/**"      class= "Org.springframework.web.servlet.mvc.UrlFilenameViewController"/>     <bean name= "/*.html"      class= "Org.springframework.web.servlet.mvc.UrlFilenameViewController"/>     < Bean name= "/index3/*.html"      

/index1/* : can match/index1/demo, but does not match/index1/demo/demo, such as/index1/demo logical view named demo;

/index2/** : can match all sub-paths under the/INDEX2 path, such as matching/index2/demo, or/index2/demo/demo, the logical view of "/index2/demo" is named demo, and "/index2/demo/ Demo "Logical view named Demo/demo;

/*.html : can match such as/abc.html, logical view named ABC, suffix will be deleted (not just HTML);

/index3/*.html : can match/index3/abc.html, logical view name is also ABC;

The above pattern matches the Ant-style pattern used by spring WEB MVC:

    ?    Match a character, such as/index? Can match/index1, but cannot match/index or/index12         *    matches 0 or more characters, such as/index1/*, can match/index1/demo, but does not match/index1/demo/demo       * *   match 0 or more paths, such as/index2/**: can match all sub-paths under the/INDEX2 path, such as matching/index2/demo, or/index2/demo/demo              if I have the following pattern, Which one does spring choose to execute? When my request for "/long/long" is as follows:       /long/long       /long/**/abc         /long/**       /**       Spring's abstracturlhandlermapping use: the longest match takes precedence;       if the request is "/long/long" will match the first "/long/long", but the request "/LONG/ACD" will match "/long/** ", such as Request"/LONG/AA/ABC "matches"/LONG/**/ABC ", if Request"/ABC "will match"/** "     

Urlfilenameviewcontroller also provides the following properties:

prefix : generates a prefix for the logical view name;

suffix : generates a suffix for the logical view name;

    Protected string Postprocessviewname (String viewName) {                 return Getprefix () + ViewName + getsuffix ();         }   
<bean name= "/*.htm" class= "Org.springframework.web.servlet.mvc.UrlFilenameViewController" >             < Property name= "prefix" value= "test"/>             <property name= "suffix" value= "test"/>     </bean>  

When prefix="Test", suffix="test", as shown above /*.htm: can match such as/ Abc.htm, but the logical view name becomes Testabctest.

SPRINGMVC Study Summary (iii)--controller interface detailed (1)

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.