【发布时间】:2020-04-04 10:07:51
【问题描述】:
我有下面的速度模板构造
#if($no_of_entries > 1)
<strong>Its True !!</strong>
#else
<strong>Its False !!</strong>
#end
即使$no_of_entries 大于 1,比如说 10, 它也会打印 Its False !!
这意味着$no_of_entries > 1 不工作
为什么 $no_of_entries > 1 条件返回 false ?
我尝试打印$no_of_entries 的值,它打印出正确的值> 1
编辑:
我也尝试过使用下面的代码
#if( Integer.parseInt($no_of_entries) > 1)
<strong>Its True !!</strong>
#else
<strong>Its False !!</strong>
#end
但它不起作用并抛出异常 -
org.apache.velocity.exception.ParseErrorException: Encountered "Integer" at file.vm
Was expecting one of:
"[" ...
"{" ...
"(" ...
<WHITESPACE> ...
<STRING_LITERAL> ...
"true" ...
"false" ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<IDENTIFIER> ...
"{" ...
<WHITESPACE> ...
【问题讨论】:
-
no_of_entries对象是什么?列表/整数/... -
哦。它的字符串。这就是为什么它似乎不起作用。让我通过 int 并检查
-
您使用的是哪个版本的 Velocity?
标签: velocity velocity-template-language