- 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