1、判斷Velocity 是否為null
方法一 、 #ifnull() 或 #ifnotnull()
Eg: #ifnull ($XXX)
Warn:要使用這個(gè)特性必須在velocity.properties 文件中加入:
userdirective = org.apache.velocity.tools.generic.directive.Ifnull
userdirective = org.apache.velocity.tools.generic.directive.Ifnotnull
方法二 、$null.isNull()
Eg:#if($null.isNull())
推薦使用方法二,特別是在判斷集合對象為null時(shí),灰常有用。
2、判斷Velocity是否為空
判斷空:#if (! $xxx)
判斷非空: #if ($xxx)
3、更詳細的介紹請參考:
http://wiki.apache.org/velocity/VelocityNullSupport
http://wiki.apache.org/velocity/CheckingForNull
聯(lián)系客服