【问题标题】:How to design the HTML email body using Thymeleaf如何使用 Thymeleaf 设计 HTML 电子邮件正文
【发布时间】:2019-04-17 19:50:43
【问题描述】:

是否可以在不使用 MVC 路由的情况下通过 Thymeleaf 创建 HTML 电子邮件正文?

【问题讨论】:

  • 你有什么问题?
  • 您好,欢迎来到 Stack Overflow。您注意到您的问题被否决了。那是因为我们大多数人通常都想知道您的问题是什么。您能否稍微扩展您的问题,并清楚地包括您的问题是什么。示例代码总是一个好的开始。看看How to Asktour。您可以点击问题下方的编辑edit您的问题。

标签: java spring spring-boot thymeleaf


【解决方案1】:

您可以在此处找到如何实现此目的的示例。

@Bean
public ITemplateEngine htmlTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
templateEngine.setTemplateResolver(templateResolver);
return templateEngine;
}

接下来创建如下所示的上下文

final Context ctx = new Context();

将字符串/对象插入到上下文中。

String inLineMessage = "String/Object to insert in HTML";
ctx.setVariable("inLineMessage ", commitAllocationResponse);

调用方法

String html = htmlTemplateEngine.process("//templates//EmailTemplate.html", ctx);

百里香中的内置函数

check the size of list
th:if="${#lists.size(exampleList)} > 0">
//String equals check
th:if="${megaDetails.megaType } eq 'SFFIXMEGA' or ${megaDetails.megaType } eq 
     'MFFIXMEGA' "
Aggregate the varible in list
#aggregates.sum(commitAllocationResponse.allocatedMegas.![feeDollars])

【讨论】:

  • 我很疑惑,你是不是回答了自己的问题?或者这是问题的一部分?
  • 我回答了我自己的问题。如果任何机构需要帮助,他们可以使用此代码作为示例
猜你喜欢
  • 2017-05-02
  • 2013-09-04
  • 1970-01-01
  • 2017-08-03
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多