在講解HandlerExecutionChain之前,先大致了解下SpringMVC的核心開發步驟:
在web.xml中部署DispaterServlet,並配置springmvc.xml等檔案;
將映射檔案要求到處理器HandlerMapping;
HandlerMapping會把請求映射為HandlerExecutionChain類型的handler物件;
將handler物件作為參數傳遞給HandlerAdapter的實例化對象,呼叫其handler方法會產生一個ModelAndView物件;
透過ViewResolver視圖解析器,將上一步驟中產生的ModelAndView解析為View;
DispatcherServlet根據取得到View,將視圖傳回給使用者。
HandlerExecutionChain類別比較簡單,好理解。
============================================== ============================
HandlerExecutionChain {
========= ==================================================== =============
下面是類別的部分屬性。
List<HandlerInterceptor>
================================= =========================================
applyPreHandle(HttpServletRequest request, HttpServletResponse response) = (! ( i = 0; i < interceptors.length; i++= (!interceptor.preHandle(request, response, .interceptorIndex =
======================================== =================================
applyPostHandle(HttpServletRequest request, HttpServletResponse response, ModelAndView mv) = (! ( i = interceptors.length - 1; i >= 0; i--=
/** * 这个方法只会执行preHandle()方法已经成功执行并且返回true的拦截器中的postHandle()方法。 */void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, Exception ex)throws Exception { HandlerInterceptor[] interceptors = getInterceptors();if (!ObjectUtils.isEmpty(interceptors)) {for (int i = this.interceptorIndex; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i];try { interceptor.afterCompletion(request, response, this.handler, ex); }catch (Throwable ex2) { logger.error("HandlerInterceptor.afterCompletion threw exception", ex2); } } } }
以上是對HandlerExecutionChain類別的實例講解的詳細內容。更多資訊請關注PHP中文網其他相關文章!