ssm 框架中适配器标签做用

目录结构:

    

application-mvc.xml配置文件:

<?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:

@Controller
@RequestMapping("user")
public class TestController {

   @RequestMapping("dologin")
    public  String test(String userCode,String userPassword){

       return "login";
   }

当浏览器输入localhost:8080/user/dologin会显示404页面

若是配置文件中将以下标签去掉能够访问成功,若是加上会报404

<mvc:resources mapping="/statics/**" location="/statics/"/>

这里就显示适配器做用了,咱们将配置文件中加上适配器标签便可访问成功,配置文件以下

<?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>
相关文章
相关标签/搜索