无法使用Spring Boot thymeleaf加载图像 [英] Can't load image with spring boot thymeleaf
问题描述
我对Spring Boot还是陌生的,它紧随 Guru spring框架教程.
I'm very new to spring boot and following Guru spring framework tutorial.
我简单的spring boot应用程序成功运行,并且我的控制器工作正常. 我已经用thymeleaf来显示html页面,并使用了一些 bootstrap css .一切正常,但其中一个html页面中有一个图像标签. Thymeleaf在运行应用程序时显示正确的页面,但未显示图像.我对此进行了搜索,并将图像放在/resources/static/images下.这是我的项目结构:
My simple spring boot application runs successfully and my controller works fine. I have used thymeleaf to show html pages and used some bootstrap css.everything works fine but an image tag that I have in one of my html pages. Thymeleaf shows the correct page when I run the app but image is not shown.I googled about this and put my images under /resources/static/images.This is my project structure :
我也已将同一张图片复制到模板目录,并使用了这两个文件,但均无法加载.
I have also copied the same image to templates directory and used both files but none can be loaded.
这是我的html文件:
This is my html file :
这是我运行应用程序时得到的:
And this is what I get when I run the application :
404找不到错误:
谁能告诉我我想念的东西吗?
Can anyone tell me what I'm missing?
推荐答案
尝试更改为
<img src="../static/images/pirate.jpg" width="1000" th:src="@{images/pirate.jpg}"/>
这篇关于无法使用Spring Boot thymeleaf加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!