对HandlerExecutionChain类的实例讲解

零下一度
零下一度 原创
2017-07-18 14:37:20 1463浏览

讲解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中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。