要排除某一个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的路径仍然会被拦截

excludePathPatterns 排除某一個controller裡面的所有路徑怎麼寫

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

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