MultiActionController默认方法名解析器
是指在请求的地址中加入指定方法名称
MultiActionController类具有一个属性methodNameResolver,方法名解析器:其具有默认值InternalPathMethodNameResolver,该解析器将方法名作为资源名称进行解析,那就意味着,我们提交请求时,要将方法名作为资源名称出现。
方法名解析器: PropertiesMethodNameResolver 是 <bean id="myMultiController" class="cn.kitty.controller.MyMultiController">的属性。
默认方法名:MultiActionController
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/*.do" value="myMultiController"></entry>
</map>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--前缀 prefix -->
<property name="prefix" value="/"></property>
<!--后缀 suffix -->
<property name="suffix" value=".jsp"></property>
</bean>
<!--注册方法名解析器-->
<bean id="propertiesmethodnameresolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/first.do">doFirst</prop>
<prop key="/second.do">doSecond</prop>
</props>
</property>
</bean>
<!-- 注册控制器 默认方法名 MultiActionController-->
<bean id="myMultiController" class="cn.kitty.controller.MyMultiController">
<property name="methodNameResolver" ref="propertiesmethodnameresolver"></property>
</bean>
</beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
</web-app>