springmvc.xml 三种方式不能针对一个controller同时使用
<?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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <!-- 1,配置handlerMapping 根据beanname找到对应的Controller --> <bean class="org.springframework.web.servlet.mvc.support.ControllerBeanNameHandlerMapping"></bean> <bean id="userController" name="/user.do" class="com.stone.controller.UserController"></bean> <!-- 2,根据简单URL来查找Controller --> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/userInfo.do">userController</prop> </props> </property> </bean> <bean id="userController" class="com.stone.controller.UserController"></bean> <!-- 3,控制类的类名访问Controller,访问时类名首字母需要小写 --> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"></bean> <bean class="com.stone.controller.UserController"></bean> <!-- 配置视图 解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 前缀和后缀 --> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
时间: 2024-10-12 02:57:08