欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  Java

对HandlerExecutionChain类的实例讲解

程序员文章站 2022-04-07 08:11:59
...
讲解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类的实例讲解的详细内容,更多请关注其它相关文章!