spring-mvc xml-based configuration

Configuring web.xml

    <!--配置spring-MVC拦截-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

 

spring configuration file: DispatcherServlet-servlet.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: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- 3.2.xsd-context 
        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. configure the processor mapping, springmvc default handler mapper 
             BeanNameUrlHandlerMapping: the name attribute of the bean url to find handlerController -> 
    < the bean class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" > </bean > 

    ! <- according to a simple url browser url match the key, key is to find the Controller id Controller -> 
    <-! Note: not used -> 
<-!     <bean class = "org.springframework. web.servlet.handler.SimpleUrlHandlerMapping "> 
        <Property name =" Mappings "> 
            <The props> 
                <prop Key =" / user1.do "> UserController </ prop> 
                <prop Key =" / user2.do "> UserController </ prop> 
                <prop Key = "/ user3.do"> UserController </ prop> 
            </ The props> 
        </ Property> 
    </ the bean> -> 
    <-! class name (MyController by) The class name.do to access the class name first letter lowercase, test results if the class name appears in the middle behind the interception of capital will fall -> 
    < bean class= "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" > </ the bean > 

    <-! 2. configure the processor configured adapter performs the Controller -> 
    < the bean class = "org.springframework.web.servlet.mvc .SimpleControllerHandlerAdapter " > </ the bean > 

    <-! can coexist with the above processing adapter, the difference is to achieve HttpRequestHandler interface, the interface returns no value -> 
    < the bean class =" org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter " > </ the bean > 


    <-! 3. configure a controller -> 
    < the bean name = "/ userController.do" class="com.royal.backoffice.web.controller.UserController"></bean>

    <!-- 4.配置springmvc视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

Guess you like

Origin www.cnblogs.com/royal6/p/12022984.html