1.springboot拦截器使用
(1)创建自定义的拦截器类并且继承HandlerInterceptor
(2)重写preHandler方法
这个方法里面写拦截器的逻辑
(3)
自定义拦截器的配置,但是有几种配置方式,我选择java代码进行配置
这就是继承WebMvcConfigurerAdapter类
并且重写addInterceptors方法
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(webInterceptor).addPathPatterns("/**" ).excludePathPatterns("/login/**","/web/login","/web/register","/web/VerificationsCode");
super.addInterceptors(registry);
}
这里要注意excludePathPatterns方法里面的参数”/login/**“,这个目录如果你是存放静态资源,你就要加上/**,否则访问不到,依然会被拦截
但是如果只是控制类的路径,当然就不用加/**啦