SPRINGMVC Basics-Mastering three types of processors

Source: Internet
Author: User

With the widespread use of SPRINGMVC, many of its useful and effective functions should be more well-known, the following describes the SPRINGMVC three kinds of processors:

One, Beanname processor (default)

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd "><!--Beamname Processor mapping the first default, you can not write---<bean id= "beannameurlhandlermapping"class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" > <!--sort use, if there is a conflict with which controller will prevail, the smaller the value, the higher the--&        Gt <property name= "order" value= "0" ></property> </bean> <!--Controller--<bean name= "/home.ac tion "class= "Cn.cfs.springmvc.controller.HomeController" > </bean> <!--internal Resource View resolver prefix + logicname + suffix- <bean name= "Internalresourceviewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/ web-inf/jsps/"></property> <property name=" suffix "value=". jsp "></property> &LT;/BEAN&GT;&L T;/beans>

Note: This processor is the default processor for SPRINGMVC, which controls which action class (Class of control layer, controller Class) corresponds to the access request path through the bean's Name property. It is worth noting that the 3.0 was not used in the name of the write/backslash, the 3.0 version after the need to add

Second, simple processor (for multiple request path binding the same controller)

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd "><!--Simple processor mapping the second, simple configuration, different path requests correspond to the same action case--<bean id= "simpleurlhandlermapping"class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > <property name= "Mappings" > <props> <prop key= "/a.action" >test</prop> <prop key= "/b.action" >test </prop> <prop key= "/c.action" >test</prop> </props> </property&        Gt <!--sort use if there is a conflict with which controller is <property name= "order" value= "0" ></property> </bean> &L t;! --Controller--<bean id= "test" name= "/home.action"class= "Cn.cfs.springmvc.controller.HomeController" > </bean> <!--internal Resource View resolver prefix + logicname + suffix- <bean name= "Internalresourceviewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/ web-inf/jsps/"></property> <property name=" suffix "value=". jsp "></property> &LT;/BEAN&GT;&L T;/beans>

Note: This processor is determined by the key in prop to determine the specific request jump path, the following value corresponding to the Controller ID

Third, ClassName (class name) processor

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd "><!--ClassName Processor mapping the third type according to the Controller's class name to automatically map, access when the class name first letter needs lowercase, if the class naming specification, for example: HomeController can omit the controller, directly knocked Home.action can access-- > <bean id= "controllerclassnamehandlermapping"class= "Org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > <!--sort use, if there is a conflict with which controller will prevail --<property Name= "Order" value= "2" ></property> </bean> <!--Controller--<b Eanclass= "Cn.cfs.springmvc.controller.HomeController" > </bean> <!--internal Resource View resolver prefix + logicname + suffix- <bean name= "Internalresourceviewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/ web-inf/jsps/"></property> <property name=" suffix "value=". jsp "></property> &LT;/BEAN&GT;&L T;/beans>

Note: This processor is defined by the name of the controller class you define to do the mapping, you must pay attention to access the class name when the first letter to lowercase, if the class name is very canonical, such as HomeController then the controller can be omitted, Directly with home.action to access, notice me here Web. XML is configured in the Dispatcherservlet mapping intercept is a request with the suffix. Action so access is home.action if configured Yes/ The slash does not need to take the. Action

SPRINGMVC Basics-Mastering three types of processors

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.