1、新建拦截器 -- 例:
新建一个LoginInterceptor拦截器实现implements HandlerInterceptor,导入spring-boot- starter-web,复写HandlerInterceptor里面的preHandle方法
2、新建一个配置类 -- 例:
新建配置类想要生效就需要加上@Component注解
新建配置类实现WebMVCConfigurer,实现里面的AddInterceptors方法,然后通过参数registry进行addInterceptor,这里new 一个自己创建的LoginInterceptor
然后可以addPathPatterns,过滤所有请求("/**")
排除路径 -- excludePathPatterns("js/**") 排除静态资源路径