在学习 开涛的Spring MVC 有一处不明白,就是 spring MVC 中为什么要加一个HandlerAdapter?
<!-- HandlerMapping -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<!-- HandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<!-- ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 处理器 -->
<bean name="/hello" class="cn.javass.chapter2.web.controller.HelloWorldController"/>
上面的配置中,通过/hello这个url的映射已经可以找到对应的HelloWorldController,直接调用其方法不行吗?
为什么要加一层 HandlerAdapter,然后通过HandlerAdapter 来调用 Controller的控制方法?
请大家不吝赐教
谢谢
--------------------------------
找到答案,参考 [url]http://stackoverflow.com/questions/23325111/spring-mvc-handlermapping-vs-handleradapter[/url]
Since introduction of RequestMappingHandlerMapping and RequestMappingHandlerAdapter in Spring 3.1 the distinction is even simpler: RequestMappingHandlerMapping finds the appropriate handler method for the given request. RequestMappingHandlerAdapter executes this method, providing it with all the arguments.
<!-- HandlerMapping -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<!-- HandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<!-- ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 处理器 -->
<bean name="/hello" class="cn.javass.chapter2.web.controller.HelloWorldController"/>
上面的配置中,通过/hello这个url的映射已经可以找到对应的HelloWorldController,直接调用其方法不行吗?
为什么要加一层 HandlerAdapter,然后通过HandlerAdapter 来调用 Controller的控制方法?
请大家不吝赐教
谢谢
--------------------------------
找到答案,参考 [url]http://stackoverflow.com/questions/23325111/spring-mvc-handlermapping-vs-handleradapter[/url]
Since introduction of RequestMappingHandlerMapping and RequestMappingHandlerAdapter in Spring 3.1 the distinction is even simpler: RequestMappingHandlerMapping finds the appropriate handler method for the given request. RequestMappingHandlerAdapter executes this method, providing it with all the arguments.