在写模版文件判断数据是否为空的时候,想当然的写成了下面的代码。
#if(${data} != null)
#end
结果Velocity解析时抛出了如下错误:
Caused by: org.apache.velocity.exception.ParseErrorException: Encountered "null" at generator file[line 7, column 27]
一查Velocity的语法说明,原来Velocity判断null和java是不一样的。
总统上说,判断是否为null有下面几种方法:
userdirective = org.apache.velocity.tools.generic.directive.Ifnull
userdirective = org.apache.velocity.tools.generic.directive.Ifnotnull


加载中…