0
Map<String, String> model = new HashMap<String, String>();
model.put("A", "1");
model.put("b", "2");
model.put("c", "3");
try{
 content.append(FreeMarkerTemplateUtils.processTemplateIntoString(configuration.getTemplate(ftlName), model));
...

Ftl 文件如下所示:

<html><head></head><body>
${model["A"]}

<#list model?keys as prop>
    ${model[prop]}
</#list>
</body>
</html>

无论我收到错误消息:

Expression model is undefined on line 6, column 3 in vslEmail.ftl.
The problematic instruction:
----------
==> ${model["A"]} [on line 6, column 1 in vslEmail.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression model is undefined on line 6, column 3 in vslEmail.ftl.

如果我删除尝试model仅使用列表指令访问,我会得到同样的错误......任何帮助表示赞赏

4

1 回答 1

1

万一其他人像我一样愚蠢地困惑,你必须在 FTL 中这样做:

<html><head></head><body>
${A}
</body>
</html>

或使 A 成为哈希图而不是字符串并循环遍历它,而不是“顶部”模型对象。

于 2012-04-20T10:52:17.690 回答