spring boot 拦截器使用

110 阅读1分钟

InterceptorConfig.java


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;

    @Value("${intercept.url}")
    String interceptURL;

    /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //排除登录请求
        String []urls = interceptURL.split(",");
        List<String> urlList =new ArrayList<>(Arrays.asList(urls));
        registry.addInterceptor(loginInterceptor).excludePathPatterns(urlList);
    }
}

 本文已参与「新人创作礼」活动,一起开启掘金创作之路