【问题标题】:FreeMarker: Expected a boolean, but this evaluated to a numberFreeMarker:预期为布尔值,但这评估为一个数字
【发布时间】:2014-03-16 13:38:30
【问题描述】:

我有一个模板:

<#if result.numFound > 10> 
  (some data)
</#if>

这给了我解析错误:

For "#if" condition: Expected a boolean, but this evaluated to a number

result.numFoundInteger。 我读过documentation,也许我遗漏了什么……

【问题讨论】:

  • 我推荐你看看 rythm 模板引擎,看看它有多简单:rythmengine.org/doc/directive.md#if
  • 别担心,因为我是这个产品的作者 ;-)。顺便说一句,您可以通过fiddle.rythmengine.org进行在线体验
  • 您可以使用[] 代替&lt;&gt;。在我看来,这要好得多。要使用 [],只需使用 [#ftl] 开始您的模板。

标签: java template-engine freemarker


【解决方案1】:

您错过了文档中的最后几行 :)。

How to test if x is greater than 1? <#if x > 1> will be wrong, as FreeMarker will 
interpret the first > as the end of the tag. Thus, either write <#if (x > 1)> or <#if x &gt; 1>.

【讨论】:

  • 看来我很想念他们...我是一周前写的,但我会再写一次——我讨厌星期一。谢谢! :)
猜你喜欢
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2022-11-10
  • 2011-08-28
  • 1970-01-01
  • 2013-11-11
  • 2011-07-31
  • 2012-11-22
相关资源
最近更新 更多