要排除某一个 controller 里面的所有路径,可以使用'excludePathPatterns'方法,将该 controller 的路径加入到排除列表中。

假设该 controller 的路径为'/api/example',代码如下所示:

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new YourInterceptor())
                .excludePathPatterns("/api/example/**");
    }
}

在上述代码中,'YourInterceptor'是你自定义的拦截器,'excludePathPatterns'方法接受一个字符串数组,可以传入多个路径,使用'/**'通配符来匹配该 controller 下的所有路径。这样就可以排除该 controller 的所有路径,其他 controller 的路径仍然会被拦截。

Spring Boot 拦截器排除特定 Controller 路径

原文地址: https://www.cveoy.top/t/topic/qrSG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录