springboot设置资源文件的访问路径,并判断Windows服务器还是linux服务器
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) { //如果是Windows系统
registry.addResourceHandler("/upload/**")
.addResourceLocations("file:E://date/"); //媒体资源绝对路径
} else { //linux 和mac
registry.addResourceHandler("/upload/**")
.addResourceLocations("file:/usr/local/project/upload/"); //媒体资源绝对路径
}
super.addResourceHandlers(registry);
}