1.配置类
2.除了/second,拦截所有请求,
---------------------------------------------------------------------------------------------------------------
@Configuration public class MyWebMvcConfig extends WebMvcConfigurationSupport { @Override protected void addInterceptors(InterceptorRegistry registry) { // 拦截/first请求URI // registry.addInterceptor(new SomeInterceptor()).addPathPatterns("/first/**"); // 拦截所有请求,除了/second请求URI registry.addInterceptor(new SomeInterceptor()) .addPathPatterns("/**") .excludePathPatterns("/second/**"); } }
public class SomeInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { System.out.println("执行拦截器方法"); return true; } }