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

猜你喜欢

转载自www.cnblogs.com/widget90/p/12425751.html
今日推荐