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>
相關文章
相關標籤/搜索