美文网首页SpringBootJava
SpringBoot 拦截器的使用

SpringBoot 拦截器的使用

作者: maxzhao_ | 来源:发表于2019-03-05 23:27 被阅读0次

  • 使用注解@Configuration配置拦截器
  • 继承WebMvcConfigurerAdapterSpringBoot2.0以后可以直接实现WebMvcConfigurer接口,这涉及到 JDK8Interface 新特性
  • 重写addInterceptors添加需要的拦截器地址
registry.addInterceptor(new OneInterceptor())
.addPathPatterns("/testController/**");
// 拦截多个接口
// registry.addInterceptor(new OneInterceptor())
.addPathPatterns("/testController/**")
.addPathPatterns("/test2Controller/**");
// 拦截所有接口
// registry.addInterceptor(new OneInterceptor())
.addPathPatterns("/*/**");
super.addInterceptors(registry);
  • 添加拦截器类实现HandlerInterceptor,比如OneInterceptor

本文地址:https://www.jianshu.com/p/d557885b022a

相关文章

网友评论

    本文标题:SpringBoot 拦截器的使用

    本文链接:https://www.haomeiwen.com/subject/htzauqtx.html