spring - 无法使用 Spring Boot thymeleaf 加载图像

标签 spring spring-mvc spring-boot thymeleaf

我对 Spring Boot 很陌生,正在关注 Guru spring framework教程。
我的简单 spring boot 应用程序运行成功,我的 Controller 工作正常。
我使用 thymeleaf 来显示 html 页面并使用了一些 引导 CSS .一切正常,但我的一个 html 页面中有一个图像标签。
当我运行应用程序时,Thymeleaf 显示了正确的页面,但没有显示图像。我搜索了这个并将我的图像放在/resources/static/images 下。这是我的项目结构:
enter image description here
我还将相同的图像复制到模板目录并使用了这两个文件,但都无法加载。
这是我的 html 文件:
enter image description here
这就是我运行应用程序时得到的:
enter image description here
404 未找到错误:
enter image description here
谁能告诉我我错过了什么?

最佳答案

尝试更改为

<img src="../static/images/pirate.jpg" width="1000" th:src="@{images/pirate.jpg}"/>

关于spring - 无法使用 Spring Boot thymeleaf 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51083414/

相关文章:

java - 将数据库任务与 Spring petclinic 应用程序分离

java - Restful Spring postForObject 缺少所有属性值

spring-boot - 如何以编程方式从 spring-boot-actuator 获取指标?

tomcat - 在 tomcat 中部署 WAR

java - Spring Web 应用程序健康检查

Spring中的Java NoSuchMethodException(当我创建了一个构造函数时)

java - 如何使用 Spring Boot Rest 的自定义异常?

arrays - 使用 Spring MVC 从 Jquery ajax 方法返回字符串数组

java - 未找到 HTTP 请求与 URI 的映射

java - log4j 漏洞 - Sleuth 依赖