velocity判斷字段為空


方法 1: 對null和false有效

#if( ! $car.fuel )


方法 2: 對null和""有效
#if( "$!car.fuel" == "" )
如果判斷字段為空:
#if( "$car.fuel" == "" )


組合 方法 1 and 2,判斷字段只能是null
#if ((! $car.fuel) && ("$!car.fuel" == ""))


方法 4: 使用工具檢測,詳見:http://wiki.apache.org/velocity/NullTool
#if( $null.isNull($car.fuel) )


方法 5: 使用自身方法檢測
#if( $car.fuelEmpty )
car類實現isFuelEmpty()方法即可
public boolean isFuelEmpty()
{
  // return true if fuel is empty.
}


方法 6: 使用自定義指令. cf. IfNullDirective, IfNotNullDirective
#ifnull( $car.fuel )
#ifnotnull( $car.fuel )
必須在velocity.properties.中注冊:
userdirective = org.apache.velocity.tools.generic.directive.Ifnull
userdirective = org.apache.velocity.tools.generic.directive.Ifnotnull

 

詳見:http://wiki.apache.org/velocity/CheckingForNull


————————————————
版權聲明:本文為CSDN博主「猿敲月下碼」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/thc1987/article/details/52091843


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM