0

我有以下速度模板构造

#if($no_of_entries > 1)          
    <strong>Its True !!</strong>
#else
    <strong>Its False !!</strong>
#end

即使 大于 1比如 10 ,$no_of_entries它也会打印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> ...
4

1 回答 1

0

如果它是一个数字,它应该可以工作,如果它是一个字符串,则将其解析为 Integer

#set($Integer = 0)
#if($Integer.parseInt($no_of_entries) > 1) 

或者如果它是一个列表使用size()方法

#if($no_of_entries.size() > 1) 
于 2019-12-11T08:13:52.370 回答