在拦截器的配置拦截路径类中添加
@Configuration
public class MyInterceptorConfig extends WebMvcConfigurationSupport {
//添加需要拦截的请求
@Override
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MyInterceptor()).addPathPatterns("/admin/**");
super.addInterceptors(registry);
}
//防止拦截静态资源
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
//文件磁盘图片url 映射
//配置server虚拟路径,handler为前台访问的目录,locations为files相对应的本地路径
registry.addResourceHandler("/image/**")
.addResourceLocations("file:E://upload/");
//默认访问static文件
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
super.addResourceHandlers(registry);
}
}