SpringMVC 流程(3)-- HandlerAdapter
2015-07-30 10:52
645 查看
在上一篇《SpringMVC 流程(2)-- HandlerMapping》我们知道,DispatcherServlet的流程首先会得到一个HandlerExecutionChain对象,也就是一个拦截器链,那么下一步,就要使用到HandlerAdapter。一. HandlerAdapterPs:首先,最直观的就是从名字就可以看出,使用了一个策略模式(具体策略模式可以自行查找相关资料)。1.1 在HandlerAdapter接口,有一个非常重要的方法handle()方法,该方法会执行我们指定的处理请求的方法,如下:
public interface HandlerAdapter {
boolean supports(Object handler);
/**
* Use the given handler to handle this request.
* The workflow that is required may vary widely.
* @param request current HTTP request
* @param response current HTTP response
* @param handler handler to use. This object must have previously been passed
* to the {@code supports} method of this interface, which must have
* returned {@code true}.
* @throws Exception in case of errors
* @return ModelAndView object with the name of the view and the required
* model data, or {@code null} if the request has been handled directly
*/
ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;
long getLastModified(HttpServletRequest request, Object handler);
}1.2 我们平常使用 SpringMVC 很多时候都是使用注解来标注我们具体的处理方法,因为比较简单方便,其实这也是一种策略。但是,除了这种方式,还有其他的方式,不一定非要用注解,比如说还可以用 the WebFlow FlowExecutor或者 Adobe BlazeDS MessageBroker这些策略来找到我们具体的处理方法(这两种方式我也暂时不太了解)。那么,HandlerAdapter的就允许我们在这些策略之间切换。这也是HandlerAdapter的最主要的作用。再分析下HandlerMapping和Handler,从我个人理解来看,HandlerMapping相当于找到我们的这个处理类,而HandlerAdapter相当于找到我们具体的方法,并且能够执行handle方法来启动。参考:1.http://www.jpalace.org/document/34/spring-mvc-tutorial#section9
相关文章推荐
- 详解JavaScript的策略模式编程
- 学习php设计模式 php实现策略模式(strategy)
- 关于.NET Framework中的设计模式--应用策略模式为List排序
- Java策略模式的简单应用实现方法
- Java设计模式之策略模式(Strategy模式)介绍
- java实现策略模式使用示例
- 设计模式-策略模式
- 策略模式之一
- java设计模式之策略模式
- 策略模式-设计模式(二)
- “精灵(sprite)”对象设计
- Strategy 模式
- head first python 实战
- 设计模式-策略模式
- 设计模式二 策略模式
- 策略+简单工厂模式
- KMP算法java实现之策略模式
- 策略模式(未完成)(未看代码,只填了使用场景)
- 设计模式--浅谈策略模式
- 设计模式-策略模式