有没有人知道我如何单独使用 XML 配置来实现多动作控制器。使用注释,它工作得很好。只是想知道,是否可以单独使用 xml 配置谢谢
问问题
659 次
1 回答
1
尝试这样的事情:
WEB.XML
<web-app>
<servlet>
<servlet-name>xxxxServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xxxxServlet</servlet-name>
<url-pattern>*.process</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>xxxxServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.do</welcome-file>
</welcome-file-list>
</web-app>
xxxxxServlet-servlet.xml
<beans>
<bean id="urlHandler"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings">
<map>
<entry key="/validate.process" value="multiActionController"/>
<entry key="/sayHello.do" value="multiActionController"/>
<entry key="/index.do" value="multiActionController"/>
</map>
</property>
</bean>
<bean id="multiActionController" class="controller.MyController" >
<property name="methodNameResolver" ref="myResolver" /> </bean>
<bean id="myResolver"
class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"
lazy-init="default">
<property name="mappings">
<props>
<prop key="/validate.process">validateLogin</prop>
<prop key="/index.do">goToHome</prop>
<prop key="/sayHello.do">sayHello</prop> </props>
</property>
</bean>
</beans>
于 2013-06-14T02:49:20.007 回答