1. Corresponding Bean via URL
<!-- Configure Handlermapper mapper --> < bean class = " Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping " /> <!-- Configure controller custom controllers --> < bean name = "/hello.do" class =" Cn.sxt.controller.HelloController " />
With the above configuration, access to hello.do accesses the bean with the ID hello.do, which is suitable for small systems.
If you add a handleradapter configuration, you do not need to.
<!---<class= " Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter "/>
2. Assigning a bean to a URL
<Beanclass= "Org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> < Propertyname= "Mappings"> <Props> <propKey= "/hello.do">Hellocontroller</prop> </Props> </ Property></Bean><BeanID= "Hellocontroller"class= "Cn.sxt.controller.HelloController"></Bean>
This type of configuration can also use wildcards, and when accessing Hello.do, Spring assigns the request to the Hellocontroller processing
3.URL Matching Bean
<class= " Org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping "></Bean ><!--<name= " Hellocontroller " class=" Cn.sxt.controller.HelloController"></ Bean>
4. Annotations
<!-- the spring container scans all classes under the specified package, if there are annotations on the class - < base-package= "Cn.sxt.controller"/>
//developing spring MVC with annotations//with this note, the spring container will create a Bean object based on the annotation. The object's ID is the class name (lowercase first letter)//<bean id= "Hellocontroller" class= "Cn.sxt.controller.HelloController"/>@Controller Public classHellocontroller {//you can specify that the requested URL is mapped to the method by using the @requestmapping annotation@RequestMapping (value= "/hi.do") PublicModelandview Hello () {modelandview mv=NewModelandview (); Mv.setviewname ("Hello"); Mv.addobject ("MSG", "annotation------"); returnMV; }}
SPRINGMVC Framework Learning Note (3)--controller configuration Rollup