欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

對handlerexecutionchain類的深入理解

 更新時間:2017年07月04日 08:36:07   投稿:jingxian  
下面小編就為大家?guī)硪黄獙andlerexecutionchain類的深入理解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

HandlerExecutionChain類比較簡單,好理解。

/*
 * 處理器執(zhí)行鏈由處理器對象和攔截器組成。
 */
public class HandlerExecutionChain {

下面是類的部分屬性。

private final Object handler; //處理器對象。

  private HandlerInterceptor[] interceptors; //攔截器數(shù)組

  private List<HandlerInterceptor> interceptorList; //攔截器列表
/**
   * Apply preHandle methods of registered interceptors.
   * @return {@code true} if the execution chain should proceed with the
   * next interceptor or the handler itself. Else, DispatcherServlet assumes
   * that this interceptor has already dealt with the response itself.
   * 執(zhí)行已經(jīng)注冊的攔截的 preHandle()方法。如果返回true,則執(zhí)行鏈可以執(zhí)行下一個攔截器的preHandle()方法或 handler 自身。
   * 否則,
   */
  boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
      for (int i = 0; i < interceptors.length; i++) {
        HandlerInterceptor interceptor = interceptors[i];
        if (!interceptor.preHandle(request, response, this.handler)) {
          triggerAfterCompletion(request, response, null);
          return false;
        }
        this.interceptorIndex = i;
      }
    }
    return true;
  }
/*
   * 執(zhí)行已經(jīng)注冊的攔截器 postHandle()方法。
   */
  void applyPostHandle(HttpServletRequest request, HttpServletResponse response, ModelAndView mv) throws Exception {
    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
      for (int i = interceptors.length - 1; i >= 0; i--) {
        HandlerInterceptor interceptor = interceptors[i];
        interceptor.postHandle(request, response, this.handler, mv);
      }
    }
  }
/**
   * 這個方法只會執(zhí)行preHandle()方法已經(jīng)成功執(zhí)行并且返回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類的深入理解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • java“與”符號寫法與用法

    java“與”符號寫法與用法

    在本篇文章里小編給大家整理的是關(guān)于java“與”符號寫法與用法,對此有需要的朋友們可以學習下。
    2020-02-02
  • SpringMVC和Ajax的交互詳解(手工處理)

    SpringMVC和Ajax的交互詳解(手工處理)

    Ajax即異步的?JavaScript和XML,是一種無需重新加載整個網(wǎng)頁的情況下,能夠更新部分模塊的網(wǎng)頁技術(shù),下面這篇文章主要給大家介紹了關(guān)于SpringMVC和Ajax交互的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-08-08
  • 徹底理解Java中this 關(guān)鍵字

    徹底理解Java中this 關(guān)鍵字

    這篇文章主要介紹了徹底理解Java中this 關(guān)鍵字的相關(guān)資料,非常不錯,具有參考價值,需要的朋友可以參考下
    2016-05-05
  • SpringMVC中DispatcherServlet的HandlerMapping詳解

    SpringMVC中DispatcherServlet的HandlerMapping詳解

    這篇文章主要介紹了SpringMVC中DispatcherServlet的HandlerMapping詳解,上回說的Handler,我們說是處理特定請求的,也就是說,不是所有的請求都能處理,那么問題來了,我們怎知道哪個請求是由哪個Handler處理的呢,需要的朋友可以參考下
    2023-10-10
  • 最新評論