SpringMVC configured URL mapping process in three ways

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

Published 35 original articles · won praise 7 · views 2112

Guess you like

Origin blog.csdn.net/weixin_40605573/article/details/103843351