Я использую тимилиф и весеннюю загрузку, чтобы заставить работать шаблон электронной почты. Использование библиотеки spring-boot-starter-thymelelaf. implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
Часть шаблона (которая тоже не работает) выглядит следующим образом.
<p class="highlight-status" style="margin: 0; margin-bottom: 15px; font-family: 'Montserrat', sans-serif; text-decoration: none; color: #323232; font-weight: 500; font-size: 11px; line-height: 1.45; margin-right: 16px; margin-left: 4px;" th:switch="${callout}">
<img th:case="'New'" th:src="@{img/new.jpg}" alt="New" width="104" height="22" border="0" style="display: block; margin: 0; outline: none; border: 0; font-family: 'Montserrat', sans-serif; text-decoration: none; color: #323232; font-weight: 500; font-size: 11px; line-height: 1.45;">
...
</p>
Я вызываю свой шаблон, используя Context
. и код выглядит так. String output = templateEngine.process(Constants.TEMPLATE_FILE_NAME, new Context(Locale.getDefault(), variables));
Я не могу показать это изображение в своем электронном письме. У меня есть html файл в src/main/resources/templates
и мои jpg файлы в src/main/resources/static/img
Я также пытался использовать 1) th:src="@{/img/new.jpg}"
, который выдает ошибку org.thymeleaf.exceptions.TemplateProcessingException: Link base "/img/new.jpg" cannot be context relative (/...) unless the context used for executing the engine implements the org.thymeleaf.context.IWebContext interface (template: "email_template" - line 346, col 164)
( Я думаю, я не могу просто использовать Context-relative URLs
, если я просто делаю new Context(...)
.)
и 2) th:src="@{../static/img/new.jpg}"
Как мне использовать WebContext
вместо Context
или есть другое решение для этого?