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);
}
// (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);
}
handleInternal由唯一子類RequestMappingHandlerAdapter實現。