Home  >  Article  >  Java  >  Example explanation of HandlerExecutionChain class

Example explanation of HandlerExecutionChain class

零下一度
零下一度Original
2017-07-18 14:37:201839browse

Before explaining HandlerExecutionChain, let’s have a general understanding of the core development steps of SpringMVC:

Deploy DispaterServlet in web.xml, and configure springmvc.xml and other files;

Request the mapping file to Processor HandlerMapping;

HandlerMapping will map the request to a handler object of type HandlerExecutionChain;

Pass the handler object as a parameter to the instantiation object of HandlerAdapter, and calling its handler method will generate a ModelAndView object ;

Use the ViewResolver view parser to parse the ModelAndView generated in the previous step into a View;

DispatcherServlet returns the view to the user based on the obtained View.

The HandlerExecutionChain class is relatively simple and easy to understand.

============================================== ============================

  HandlerExecutionChain {

========= ================================================== =============

The following are some attributes of the class.

  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);
                }
            }
        }
    }

The above is the detailed content of Example explanation of HandlerExecutionChain class. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn