AbstractHandlerMethodAdapter类详解 - HandlerAdapter系列二

AbstractHandlerMethodAdapter是HandlerAdapter接口的简单抽象类,实现了接口定义的方法,同时增加了执行顺序Order。

源码

public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator implements HandlerAdapter, Ordered {  
    private int order = Ordered.LOWEST_PRECEDENCE;  
    public AbstractHandlerMethodAdapter() {  
        // no restriction of HTTP methods by default  
        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);  
  
}  

版权声明:本文为JAVASCHOOL原创文章,未经本站允许不得转载。