博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦
阅读量:4045 次
发布时间:2019-05-25

本文共 871 字,大约阅读时间需要 2 分钟。

最近使用springboot2做项目发现,存放在resource/templates文件中的html中

竟然访问不到resource/static/image文件下的图片!

我想要在hellozll.html中访问seveny.png这个图片

然后使用了以下方法:(都访问失败)

<img src="../image/seveny.png"/> 

<img src="/image/seveny.png"/> 

<img src="../static/image/seveny.png"/>

<img src="/static/image/seveny.png"/>

图片无法显示,图片破了 

 解决方法:

 我们要知道Spring Boot 默认的访问静态资源的文件夹有以下四个

classpath:/staticclasspath:/publicclasspath:/resourcesclasspath:/META-INF/resources

我们可以看到,springboot默认可以找到static中的资源文件,但是我在static中又创建了image文件夹

所以啊,springboot在static中没找到seveny.png这个图片,所以就显示不了啊!

怎么解决呢!

在配置文件中加入以下配置

application.yml 的格式

spring:   resources:       static-locations: classpath:/templates/,classpath:/static/image/

application.properties 的格式

spring.resources.static-locations=classpath:/templates/,classpath:/static/image/

然后再html中直接这样访问图片,就可以啦 

 下面是运行的截图!图片好啦

 

补充:

下面是我的hellozll.html中写的内容 

 

下面是用controller中定义路径去访问hellozll.html文件

 

 

转载地址:http://bizci.baihongyu.com/

你可能感兴趣的文章
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt 创建异形窗体
查看>>
可重入函数与不可重入函数
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
输入设备节点自动生成
查看>>
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
wpa_supplicant控制脚本
查看>>
gstreamer相关工具集合
查看>>
RS232 四入四出模块控制代码
查看>>
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>