美文网首页
Filter/Interceptor/Aspect拦截Rest服

Filter/Interceptor/Aspect拦截Rest服

作者: Michael_1615 | 来源:发表于2017-12-04 20:23 被阅读0次

Filter implements Filter 可以拿到原始http请求的信息,但是拿不到处理方法的信息

init(FilterConfig filterConfig)

doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

destroy()

Interceptor implements HandlerInterceptor  可以拿到原始http请求的信息,也可以拿到处理方法的信息,但是拿不到方法的参数值

preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)

postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView arg3)

afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception)

@Aspect   可以拿到方法和方法的参数值,但是拿不到原始http请求的信息

调用流程:

如果不抛出异常的情况下:

Filter -> Interceptor -> @Aspect -> Controller

            方法:init -> preHandle -> @Aspect  -> postHandle -> afterCompletion -> destroy

如果抛出异常:

Controller -> @Aspect  -> @ControllerAdvice -> Interceptor -> Filter

相关文章

网友评论

      本文标题:Filter/Interceptor/Aspect拦截Rest服

      本文链接:https://www.haomeiwen.com/subject/udhfixtx.html