spring MVC 中爲什麼要加一個HandlerAdapter

在學習 開濤的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.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章