解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦

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

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

解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦_第1张图片

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

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

 

 

解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦_第2张图片

图片无法显示,图片破了 

 解决方法:

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

classpath:/static
classpath:/public
classpath:/resources
classpath:/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中直接这样访问图片,就可以啦 

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

解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦_第3张图片 

补充:

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

 解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦_第4张图片

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

 解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦_第5张图片

 

你可能感兴趣的:(Springboot,java,spring,spring,boot,html)