通过继承WebMvcConfigurer重写addResourceHandlers 例如当请求为
localhost:8080/photo/** 就会去访问本地资源的内容
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
@Value("${server.resource}")
/**
* 配置资源访问
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 静态资源---文件url地址
registry.addResourceHandler("/photo/**").addResourceLocations("file:"+ ConstansPropertity.filePath);
// 静态资源---视频url地址
registry.addResourceHandler("/video/**").addResourceLocations("file:"+ConstansPropertity.videoPath);
// 上传视频缩略图url地址
registry.addResourceHandler("/photo/**").addResourceLocations("file:"+ConstansPropertity.videoIcon);
//上传照片缩略图url地址
registry.addResourceHandler("/img/**").addResourceLocations("file:"+ filePath+"Camera/");
WebMvcConfigurer.super.addResourceHandlers(registry);
} private String filePath;
}