Thymeleaf电子邮件图像未显示

时间:2019-11-15 11:50:23

标签: html spring-boot thymeleaf

我在Spring Boot中使用Thymeleaf。

我正在尝试使用html模板发送邮件。

邮件正常,模板中的百里香变量被替换为完美,但是,我唯一的问题是未显示图像。就像图像不存在一样。

html模板和图像(Picture.png)位于同一文件夹中。

在模板中,我尝试过以下多次尝试:

<img src="Picture.png" />

<img src="@{Picture.png}" />

<img th:src="|cid:${imageName}|" />  // by passing the "Picture.png" in the imageName variable

<img th:src="@{Picture.png}" />

但是没有任何效果,谢谢!!

1 个答案:

答案 0 :(得分:-1)

查看Thymeleaf的文档,尤其是context-relative and server-relative url patterns的一部分。

如果您的项目根目录名为 myapp 并将其部署到Tomcat服务器中,则您的应用程序可能会以 http://localhost:8080/myapp myapp 将成为上下文名称。

因此,假设同时包含图片和html的文件夹位于:

myapp/resource/assets/(html and Picture.png exists)

动态获取图像的正确代码是:

<img src="resource/assets/Picture.png"                                   th:src="@{resource/assets/Picture.png}" />