拦截器 定义拦截器: 定义一个类实现HandlerInterceptor,实现里边的部分方法 注册拦截器: 定义一个类继承WebMvcConfigrationSupport,重写addInterceptor方法,将拦截器注册在里边 .addPath.addPathPatterns("/a/**"); //定义需要拦截的接口.excludePathPatterns("/c/**"); //定义需要放行的接口 public class firstController implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("经过了Interceptor拦截器!"); return true; } } @Configuration public class InterceptorConfig extends WebMvcConfigurationSupport { @Override protected void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new firstController()) // .addPathPatterns("/a/**"); //定义需要拦截的接口 .excludePathPatterns("/c/**"); //定义需要放行的接口 } }