简介
springMVC的处理器映射器和处理器适配器存在多种配置,因此在此专门做一个总结
常见处理器映射器、适配器的配置
springmvc多个映射器多个处理器可以并存
所有的映射器都实现了HandlerMapping接口
1、非注解的处理器映射器
org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
2、注解的的处理器映射器(必须搭配注解的适配器)
在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
在spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
1、非注解的处理器适配器
org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
要求编写实现Controller接口
HttpRequestHandlerAdapter
要求编写Handler实现HttpRequestHandler接口
2、注解的处理器适配器(必须搭配注解的映射器)
在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
在spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
常用配置
使用mvc:annotation-driven</mvc:annotation-driven>代替注解的映射器/适配器的配置
此配置默认加载了注解的映射器/适配器,并且默认加载了很多参数绑定的方法,比如json转换解析器,因此往往在实际开发中使用
其它知识点
org.springframework.web.servlet.DispacherServlet.properties配置了默认的处理器映射器、处理器适配器、视图解析器