1.写一个方法实现HandlerInterceptor
import org.springframework.web.servlet.HandlerInterceptor;
实现接口的方法可以按springmvc中一样
2.编写配置类继承WebMvcAutoConfigurationAdapter
并覆盖
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new 自己创建的拦截器类()).addPathPatterns("拦截的对象").excludePathPatterns("不拦截的对象");
}
}
拦截和不拦截对象都可以为String数组和String类型
3,当然要在类上加入@Configuration注解,标注此类为一个配置类让springboot扫描到