转自:
AbstractHandlerMethodAdapter类简介说明
下文笔者将讲述AbstractHandlerMethodAdapter类的简介说明,如下所示:
AbstractHandlerMethodAdapter是HandlerAdapter接口的简单抽象类
实现了接口定义的方法(同时预留了子类的实现接口)
同时增加了执行顺序Order
AbstractHandlerMethodAdapter的源码分析
public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator implements HandlerAdapter, Ordered { private int order = Ordered.LOWEST_PRECEDENCE; public AbstractHandlerMethodAdapter() { //默认情况下不限制HTTP方法 super(false); } @Override public final boolean supports(Object handler) { return (handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler)); } protected abstract boolean supportsInternal(HandlerMethod handlerMethod); //重写HandlerAdapter的handle方法 @Override public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return handleInternal(request, response, (HandlerMethod) handler); } //handleInternal主要做如下操作:(1)备好处理器所需要的参数(2)使用处理器处理请求(3)处理返回值,也就是将不同类型的返回值统一处理成ModelAndView类型 protected abstract ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception; @Override public final long getLastModified(HttpServletRequest request, Object handler) { return getLastModifiedInternal(request, (HandlerMethod) handler); } //提供order功能 public void setOrder(int order) { this.order = order; } @Override public int getOrder() { return this.order; } protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod); }