zoukankan      html  css  js  c++  java
  • 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页面;
    }
    }

     

    数据库中路径

     

     

    测试:

     

     

  • 相关阅读:
    shiro的授权与认证
    spring-aop
    GC选择之串行收集与并行收集
    4. Tomcat调优
    spring boot 启动 开启注解 加载 bean
    一、JavaScript实现AJAX(只需四步)
    DVWA安装
    CTF入门指南
    Metasploit 学习
    JSP笔记
  • 原文地址:https://www.cnblogs.com/devise/p/9974665.html
Copyright © 2011-2022 走看看