【发布时间】:2021-09-16 22:08:36
【问题描述】:
在我的ftl 文件中,我正在写:
<#list myDataList as myData>
<p>
<#if myData.action == 0>Added by
<#else>Removed from
</#if>
</p>
</#list>
在 java 代码中,action 的类型是 Integer。
我也试过myData.action == "0"。
调试时可以看到action == 0。
我遇到的错误:
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> myData.action [in template "email_template.ftl" at line 79, column 50]
【问题讨论】:
-
尝试使用默认值
myData.action!"0" == "0"或(myData.action)!"0" == "0" -
@user7294900 默认值不必是字符串。所以应该这样来避免任何数字格式问题(比如存在
action,然后自动转换为0.0):myData.action!0 == 0
标签: java freemarker