当前位置: 代码迷 >> 综合 >> spring MultiActionController 简单配置
  详细解决方案

spring MultiActionController 简单配置

热度:17   发布时间:2024-01-10 01:23:43.0

步骤一:

在web.xml配置

<!--该配置springmvc路由器 -->

<servlet> 
    <servlet-name>springapp</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet>

<!--指定路由的扩展名-->

<servlet-mapping> 
    <servlet-name>springapp</servlet-name> 
    <url-pattern>*.htm</url-pattern> 
</servlet-mapping>

步骤二:

springapp-servlet.xml文件中

<!--配置了/Profile.htm与哪个类进行映射-->

<bean name="/Profile.htm" class="springapp.web.ViewProfile"> 
        <property name="methodNameResolver"> 
            <ref bean="methodNameResolver" /><!—引用参数action的分解--> 
        </property> 
</bean> 
<bean name="methodNameResolver" 
        class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> 
        <property name="paramName" value="action"></property> 
</bean>

该步骤中使用了ParameterMethodNameResolver 类,用于对参数action的提取。

浏览器中输入地址:

http://192.168.7.110:8080/Example1/Profile.htm?action=contactProfile

这个url地址中就执行了ViewProfile类中的contactProfile的方法。

  相关解决方案