目录
结论:Spring拦截器在请求进入Controller进行拦截添加自己的处理逻辑,Mybatis拦截器在Mapper层的方法上进行拦截添加自己的处理逻辑。
一、Spring的拦截器
Spring的拦截器主要分两种:HandlerInterceptor、MethodInterceptor。
1.1、HandlerInterceptor接口
HandlerInterceptor是springMVC项目中的拦截器,它拦截的目标是请求的地址,比MethodInterceptor先执行。实现一个HandlerInterceptor拦截器可以实现HandlerInterceptor接口,也可以继承HandlerInterceptorAdapter类(Sping 5中已弃用,不建议使用)。
HandlerInterceptor源码如下:
public interface HandlerInterceptor {
default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return true;
}
default void postHa