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