Http://blog.chinaunix.net/uid-20415521-id-1949916.html
The handlermapping in Spingmvc (2007-05-22-11:33)
Category: Spring
Dispatcherservlet to give a request to a specific controller, it needs to consult a bean--the bean's name is "Handlermapping".
Handlermapping is to assign a URL to a controller (just like the application's Web. xml file uses <servlet-mapping> maps the URL to the servlet).
Spring comes with three kinds of handlermapping, (all handlermapping in Springmvc Implement Interface Org.springframework.web.servlet. handlermapping).
1, beannameurlhandlermapping
This is the default handlermapping of the dispatcher servlet, so simply use "URL style" to define a controller bean's name in the app context configuration file, and you can tell dispatcher Servlet what style of request should be handled by which controller, without explicitly defining a handlermapping. (Privately speaking, this is simple, but the name of the Controllerbean that is defined by the URL style is odd because the name is also the instance name of the controller Bean)
Example: If the URL style of the controller Listcoursescontroller is "Listcourses.go", then
<bean name= "/listcourses.go"
class= "Com.w3cs.vlar.ListCoursesController" >
<property name= "Couseservice" >
<ref bean= "Courceservice"/>
</property>
</bean>
Of course, before defining this controller bean, you can explicitly declare the handlermapping you are using, explicitly defined as follows:
<bean id= "Beannameurlmapping"
class= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" >
2, Simpleurlhandlermapping
This is different from beannameurlhandlermapping,simpleurlhandlermapping, which does not need to define the name of the controller bean, but instead maps the URL directly to the controller.
Since simpleurlhandlermapping is not the default handlermapping of the dispatcher servlet, this handlermapping must be explicitly defined.
The following defines a handlermapping Bean with the id "Simpleurl":
<bean id= "simpleurlmapping" class= "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name= "Mappings" >
<props>
<prop key= "/listcourses.go" >listCoursesController</prop>
<prop key= "/login.go" >loginController</prop>
</props>
</property>
</bean>
Explain:
1), simpleurlhandlermapping, with <prop> assembled a java.util.Properties named mappings.
2), the <prop> element's key property is a URL style, and the value of <prop> is the name of the controller bean that handles the URL. (and the odd name in Beannameurlmapping is the instance name of the controller Bean).
3, Commonspathmaphandlermapping
This processor maps the controller to a URL using the metadata in the controller code. But I don't use it specifically. Who knows can tell me!!!
SPRINGMVC's handlemapping