Springmvc--4 Type Mapping Processor handlermapping

Source: Internet
Author: User

    • Mapping to find controller by name of controller:beannameurlhandlermapping (default)
1. 1 Turn on the map: default is on class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" > </bean>1. 2 defines the Name property of the Bean:class= "Com.controller.HelloController" ></bean>1. 3 Interface Access URL: Consistent with the Bean's Name property value http://localhost:5080/springmvc/hello1.do
    • Mapping based on URLs find controller: Recommended for:simpleurlhandlermapping
2. 1 Turn on the map:class= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >< Property name= "Mappings" ><props><prop key= "/hello2.do" >HelloController</prop></props> </property></bean>2. 2 definition Bean:class= "Com.controller.HelloController" ></bean >2. 3 Interface URL Access: Consistent with Prop's key attribute value http://localhost:5080/springmvc/hello2.do Advantages: The controller definition is separated from the mapping and the coupling is low.
    • Mapping the Controller's class name to find controller: controllerclassnamehandlermapping
 3.1 to turn on the class name Mapping Processor:  <bean class  = " Org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping "></bean>3.2 definition bean  <bean id=" Hello3controller "class  =" Com.controller.Hello2Controller "></bean>3.3 interface URL Access: Independent of the bean's id attribute value. http:  // localhost:5080/springmvc/ hello2.do correct  http:// localhost:5080/ springmvc/hello2controller.do correct  http://  localhost:5080/springmvc/hello21111.do correct  http:// localhost:5080/springmvc/hello3.do error  Note: Use the class name to access a controller, 
    • Use annotations to map the Find controller: defaultannotationhandlermapping

Defaultannotationhandlermapping and requestmappinghandlermapping are all annotations that deal with Requestmapping,
The former is deprecated, not recommended, and the latter is used instead of the former

1. Turn on the annotation scan component: function: When I load a configuration file, scan (read) the Java file under the package we specified, look for the place where the annotation was annotated (interface, class, method, or other), and complete the initialization. <beans><!--Configuration Scan package path using annotations--><context:component-scan base- Package= "com" ></context:component-scan><!--open SPRINGMVC annotations--><beanclass= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> <beanclass= "Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" ></bean> </beans >2. Tag on class: @Controller declares that the class is a SPRINGMVC Controller3. Use on Method: @RequestMapping ("/login") declares which request the method processes eg: @Controller Public classLogin {@RequestMapping ("/login") PublicModelandview Login () {modelandview mv=NewModelandview (); Mv.setviewname ("Login"); returnmv;}}

Springmvc--4 Mapping Processor handlermapping

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.