SPRINGMVC Framework Learning Note (3)--controller configuration Rollup

Source: Internet
Author: User

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

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.