【发布时间】:2017-12-13 16:35:39
【问题描述】:
我正在使用带有一些模板的 Spring Boot 来帮助生成一些动态电子邮件。不幸的是,模板引擎没有呈现我的变量。
后端调用
public String generateProblemOfTheDay(Model model) throws IOException {
Context ctx = new Context();
ctx.setVariable("potd", "Test Value");
//Process the template with the proper context variables
String html = templateEngine.process("index", ctx);
PrintWriter pWriter = new PrintWriter(Paths.PROBLEM_OF_THE_DAY_OUTPUT, "UTF-8");
pWriter.println(html);
pWriter.close();
log.info("done!");
log.info(html);
return html;
}
我的模板片段
.
.
<tr>
<td style="font-family:'Open Sans', Arial, sans-serif; font-size:15px; line-height:18px; color:#30373b;">
<br />
<div class="question-description">
[[${potd}]]
</div>
</td>
</tr>
.
.
我不确定为什么模板引擎没有正确处理变量。这是添加变量的最佳方式吗?
我发现确实有效
<label style="font-size: 12px;padding-bottom: 1em;" th:text="${potd}">Test</label>
添加如下内容确实有效.. 我看到很多人使用标准大括号表示法没有问题,并且想知道什么地方合适。
【问题讨论】:
标签: java spring-boot thymeleaf