spring3.1之前使用org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping注解映射器。

spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping注解映射器。

spring3.1之前使用org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter注解适配器。

spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter注解适配器。

springmvc.xml配置

多个映射器可以并存,前端控制器判断url能让哪些映射器映射,就让正确的映射器处理。

<!-- 配置处理器适配器执行Controller ,springmvc默认的 SimpleControllerHandlerAdapter:执行Controller
    SimpleControllerHandlerAdapter只能适配实现了Controller接口的Controller-->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/b.do">indexController</prop>
                <prop key="/c.do">index2Controller</prop>
            </props>
        </property>
    </bean>
    <bean id="indexController" class="controller.IndexController"/>
    <bean id="index2Controller" class="controller.Index2Controller"/>

Controller层代码:

package controller;

import org.springframework.web.HttpRequestHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class IndexController implements HttpRequestHandler {
    @Override
    public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("hello","this is a HttpRequestHandler");
        req.getRequestDispatcher("/WEB-INF/jsps/index.jsp")
                .forward(req,resp);
    }
}
02-11 03:59