类 MappedInterceptor

  • 所有已实现的接口:
    HandlerInterceptor

    public final class MappedInterceptor
    extends Object
    implements HandlerInterceptor
    Contains and delegates calls to a HandlerInterceptor along with include (and optionally exclude) path patterns to which the interceptor should apply. Also provides matching logic to test if the interceptor applies to a given request path.

    A MappedInterceptor can be registered directly with any AbstractHandlerMethodMapping. Furthermore, beans of type MappedInterceptor are automatically detected by AbstractHandlerMethodMapping (including ancestor ApplicationContext's) which effectively means the interceptor is registered "globally" with all handler mappings.

    从以下版本开始:
    3.0
    作者:
    Keith Donald, Rossen Stoyanchev, Brian Clozel
    • 构造器详细资料

      • MappedInterceptor

        public MappedInterceptor​(@Nullable
                                 String[] includePatterns,
                                 HandlerInterceptor interceptor)
        Create a new MappedInterceptor instance.
        参数:
        includePatterns - the path patterns to map (empty for matching to all paths)
        interceptor - the HandlerInterceptor instance to map to the given patterns
      • MappedInterceptor

        public MappedInterceptor​(@Nullable
                                 String[] includePatterns,
                                 @Nullable
                                 String[] excludePatterns,
                                 HandlerInterceptor interceptor)
        Create a new MappedInterceptor instance.
        参数:
        includePatterns - the path patterns to map (empty for matching to all paths)
        excludePatterns - the path patterns to exclude (empty for no specific excludes)
        interceptor - the HandlerInterceptor instance to map to the given patterns
      • MappedInterceptor

        public MappedInterceptor​(@Nullable
                                 String[] includePatterns,
                                 WebRequestInterceptor interceptor)
        Create a new MappedInterceptor instance.
        参数:
        includePatterns - the path patterns to map (empty for matching to all paths)
        interceptor - the WebRequestInterceptor instance to map to the given patterns
      • MappedInterceptor

        public MappedInterceptor​(@Nullable
                                 String[] includePatterns,
                                 @Nullable
                                 String[] excludePatterns,
                                 WebRequestInterceptor interceptor)
        Create a new MappedInterceptor instance.
        参数:
        includePatterns - the path patterns to map (empty for matching to all paths)
        excludePatterns - the path patterns to exclude (empty for no specific excludes)
        interceptor - the WebRequestInterceptor instance to map to the given patterns
    • 方法详细资料

      • matches

        public boolean matches​(String lookupPath,
                               PathMatcher pathMatcher)
        Determine a match for the given lookup path.
        参数:
        lookupPath - the current request path
        pathMatcher - a path matcher for path pattern matching
        返回:
        true if the interceptor applies to the given request path
      • preHandle

        public boolean preHandle​(HttpServletRequest request,
                                 HttpServletResponse response,
                                 Object handler)
                          throws Exception
        从接口复制的说明: HandlerInterceptor
        Intercept the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler.

        DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response.

        Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.

        The default implementation returns true.

        指定者:
        preHandle 在接口中 HandlerInterceptor
        参数:
        request - current HTTP request
        response - current HTTP response
        handler - chosen handler to execute, for type and/or instance evaluation
        返回:
        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.
        抛出:
        Exception - in case of errors
      • postHandle

        public void postHandle​(HttpServletRequest request,
                               HttpServletResponse response,
                               Object handler,
                               @Nullable
                               ModelAndView modelAndView)
                        throws Exception
        从接口复制的说明: HandlerInterceptor
        Intercept the execution of a handler. Called after HandlerAdapter actually invoked the handler, but before the DispatcherServlet renders the view. Can expose additional model objects to the view via the given ModelAndView.

        DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can post-process an execution, getting applied in inverse order of the execution chain.

        Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.

        The default implementation is empty.

        指定者:
        postHandle 在接口中 HandlerInterceptor
        参数:
        request - current HTTP request
        response - current HTTP response
        handler - the handler (or HandlerMethod) that started asynchronous execution, for type and/or instance examination
        modelAndView - the ModelAndView that the handler returned (can also be null)
        抛出:
        Exception - in case of errors
      • afterCompletion

        public void afterCompletion​(HttpServletRequest request,
                                    HttpServletResponse response,
                                    Object handler,
                                    @Nullable
                                    Exception ex)
                             throws Exception
        从接口复制的说明: HandlerInterceptor
        Callback after completion of request processing, that is, after rendering the view. Will be called on any outcome of handler execution, thus allows for proper resource cleanup.

        Note: Will only be called if this interceptor's preHandle method has successfully completed and returned true!

        As with the postHandle method, the method will be invoked on each interceptor in the chain in reverse order, so the first interceptor will be the last to be invoked.

        Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.

        The default implementation is empty.

        指定者:
        afterCompletion 在接口中 HandlerInterceptor
        参数:
        request - current HTTP request
        response - current HTTP response
        handler - the handler (or HandlerMethod) that started asynchronous execution, for type and/or instance examination
        ex - any exception thrown on handler execution, if any; this does not include exceptions that have been handled through an exception resolver
        抛出:
        Exception - in case of errors