2020-12-07 14:38:48
浏览数 (1)
目录结构: application-mvc.xml配置文件: 代码语言: javascript
复制 <?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描注解-->
<context:component-scan base-package="cn.bdqn.controller"></context:component-scan>
<!--返回视图-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--静态资源映射路径-->
<mvc:resources mapping="/statics/**" location="/statics/"/>
</beans>
controller: 代码语言: javascript
复制 @Controller
@RequestMapping("user")
public class TestController {
@RequestMapping("dologin")
public String test(String userCode,String userPassword){
return "login";
}
当浏览器输入localhost:8080/user/dologin会显示404页面 如果配置文件中将如下标签去掉可以访问成功,如果加上会报404 代码语言: javascript
复制 <mvc:resources mapping="/statics/**" location="/statics/"/>
这里就显示适配器作用了,我们将配置文件中加上适配器标签即可访问成功,配置文件如下 代码语言: javascript
复制 <?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描注解-->
<context:component-scan base-package="cn.bdqn.controller"></context:component-scan>
<!--适配器-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--返回视图-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--静态资源映射路径-->
<mvc:resources mapping="/statics/**" location="/statics/"/>
</beans>