ssm 框架中适配器标签作用 <mvc:annotation-driven></mvc:annotation-driven>

限于喜欢 提交于 2019-11-29 06:25:56

目录结构:

    

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>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!