springboot中配置addResourceHandler和addResourceLocations,使得可以从磁盘中读取图片、视频、音频等

磁盘目录

WebMvcConfig的代码

//对静态资源的配置
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

   String os = System.getProperty("os.name");

   if (os.toLowerCase().startsWith("win")) {  //如果是Windows系统
      registry.addResourceHandler("/smallapple/**")
            // /apple/**表示在磁盘apple目录下的所有资源会被解析为以下的路径
            .addResourceLocations("file:G:/itemsource/smallapple/") //媒体资源
            .addResourceLocations("classpath:/META-INF/resources/");  //swagger2页面
   } else {  //linux 和mac
      registry.addResourceHandler("/smallapple/**")
            .addResourceLocations("file:/resources/smallapple/")   //媒体资源
            .addResourceLocations("classpath:/META-INF/resources/");  //swagger2页面;
   }
}


数据库中路径

测试:

springboot中配置addResourceHandler和addResourceLocations,使得可以从磁盘中读取图片、视频、音频等_第1张图片
--------------------- 
作者:wangzns 
来源:CSDN 
原文:https://blog.csdn.net/ajklaclk/article/details/80804137 
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(springboot中配置addResourceHandler和addResourceLocations,使得可以从磁盘中读取图片、视频、音频等)