Spring Boot内置Tomcat的静态资源配置(在页面中显示项目外的某个图片)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26458903/article/details/79963925

哇~我现在只想长长的舒一口气,终于解决了 ~    记录一下

好,下面开始我的第一个博客,写的不好还请大家见谅~

最近老大让我接触一下spring boot,做一个简单的项目。

我的Spring Boot项目是在官网自动生成的,目录如下:

在红线圈住的“application.properties”文件中进行配置:


application.properties:

spring.mvc.static-path-pattern=/**
web.png-path=D:/temp/picture/
spring.resources.static-locations=classpath:/static/,classpath:/templates/, file:${web.png-path}

其中“web.png-path”表示磁盘中图片存放的路径,“spring.resources.static-location”表示的是静态资源的位置,(下边的是官网给的,和我的目录不同,需要根据自己的项目目录改变一下,官网链接

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ # Locations of static resources.


index.html:

在页面用下边的代码来访问,其中“pictureFileName.png”是本地磁盘“D:/temp/picture/”目录下的图片

<img src="/pictureFileName.png" width="500" height="800"></img>


大家有哪些地方要是没有看懂,可以在下边留言






猜你喜欢

转载自blog.csdn.net/qq_26458903/article/details/79963925