SpringMVC配置URL處理映射的三種方式

<?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"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/mvc
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

       <!--1.配置url處理映射
          URL處理映射的方式有三種   【通過訪問路徑,找到  3.配置控制器中  對應的控制器】
         1. BeanNameUrlHandlerMapping:通過url名字,找到對應的bean的name的控制器即3.
         2. SimpleUrlHandlerMapping 【簡單得URL處理映射】 通過key找到bean的id的控制器
         3. ControllerClassNameHandlerMapping 【控制器的類名處理映射】 不用配置訪問路徑,
             默認的訪問路徑就是類名首字母大寫變小寫,加.do後綴
       -->
    <!--第一種-->
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

    <!--第二種-->
    <!--<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">-->
        <!--<property name="mappings">-->
            <!--<props>-->
                <!--<prop key="/user1.do">userController</prop>-->
                <!--<prop key="/user2.do">userController</prop>-->
                <!--<prop key="/user3.do">userController</prop>-->
            <!--</props>-->
        <!--</property>-->
    <!--</bean>-->

    <!--第三種-->
    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
       <!--2.配置控制器處理適配器-->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
       <!--3.配置控制器 相當於配置了一個訪問路徑 1.name="/user.do" 2.id="userController" 3.-->
    <bean   class="com.zxh.backoffice.web.controller.UserController"></bean>
       <!--4.配置資源視圖解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--前綴-->
        <property name="prefix" value="/WEB-INF/views/"/>
        <!--後綴-->
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章