美文网首页
springboot 创建虚拟目录

springboot 创建虚拟目录

作者: 谁偷吃了我的香妃红葡萄干 | 来源:发表于2018-10-10 11:07 被阅读0次

方法一:

新建一个类如下:

表示:将/file/**路径映射到D:img 下

访问方式:localhost:8080/file/1.png

@Component  

class WebConfigurer implements WebMvcConfigurer {

    @Override  

    public void addResourceHandlers(ResourceHandlerRegistry registry) {  

        registry.addResourceHandler("/file/**").addResourceLocations("file:D:/img/");  

    }  

}

方法二:

修改application.properties文件

web.filepath= D:/img

spring.resources.static-locations= classpath:/resources/,classpath:/static/,file:${web.filepath}

表示将静态资源路径映射到D:/img

访问方式:localhost:8080/1.img即可

lunix 同上 目录file:/usr/img/

相关文章

网友评论

      本文标题:springboot 创建虚拟目录

      本文链接:https://www.haomeiwen.com/subject/brhpaftx.html