Spring mvc之SimpleUrlHandlerMapping

1、配置文件如下

<bean id="method" class="com.xx.controller.xxxController" scope="prototype"/>


<!--控制层 方法与发布应用路径映射 所有控制层的方法映射全配置在这里 -->
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/urlDemo">method</prop>
<prop key="xx">xx</prop>

</props>
</property>
</bean>

2、新建一个测试类

1 public class xxxController extends MultiActionController {//或者这里可以直接实现Controller接口
2     public ModelAndView method(HttpServletRequest request,     
3             HttpServletResponse response)
4             throws Exception {
5           //......
6          return null;
7 }
8 
9 }    
测试类对应上面配置

这样配置的话我们只要对/urlDemo 这个路径进行拦截,就能进行控制他走那个控制层走什么业务逻辑了!!!

原文地址:https://www.cnblogs.com/panca/p/10896320.html