簡介
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配置了默認的處理器映射器、處理器適配器、視圖解析器