1,创建一个类,实现WebMvxConfigurer,重写addInterceptors,添加需要拦截的路径,以及放行的路径
import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class MyWebMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { try { //MyLoginInterception这个类是拦截的条件(如是否需要登录,需要单独来写,请看下面) //excludePathPatterns这个是不需要进行拦截的操作路径。 registry.addInterceptor(MyLoginInterception.class.newInstance()).addPathPatterns("/**") .excludePathPatterns("/login", "/register", "/**/*.js", "/**/*.css", "/**/*.html"); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e)