Html 图中未显示使用thymeleaf和spring

Html 图中未显示使用thymeleaf和spring,html,spring,spring-boot,thymeleaf,Html,Spring,Spring Boot,Thymeleaf,图像位于以下目录中: /src/main/resources/static/images/logo.png 这是我的HTML标签: <img width="220px" height="70px" th:src="@{/static/images/logo.png}"/> <img width="220px" height="70px" th:src="@{/static/images/bookicon.png}"

图像位于以下目录中:

/src/main/resources/static/images/logo.png
这是我的HTML标签:

<img width="220px" height="70px" th:src="@{/static/images/logo.png}"/> 
<img width="220px" height="70px" th:src="@{/static/images/bookicon.png}"/> 

但是,当我尝试访问图像时,会出现以下错误:

出现意外错误(类型=未找到,状态=404)。没有消息 可用


路径中不需要
static
。您应该使用
@{/images/logo.png}
,因为在您的情况下,默认的解析器将
/src/main/resources/static/
映射到
/
url

默认情况下,SpringBoot将提供目录中的静态内容 在中调用/static(或/public/resources/META-INF/resources) 类路径或从ServletContext的根开始


还要确保图像文件名上没有任何破折号。例如,如果有一个名为“book icon.png”的图像,则以下内容将无法编译:

<img width="220px" height="70px" th:src="@{/static/images/book-icon.png}"/> 

将文件重命名为“bookicon.png”(不带破折号)。 此代码将在以下情况下工作: