There are several ways to determine if it is null:
1. #if (! $foo) determine that $foo is empty and that non-null is #if ($foo)
2. Use #ifnull () or #ifnotnull ()
#ifnull ($foo)
To use this feature, you must include the following in the Velocity.properties file:
userdirective = org.apache.velocity.tools.generic.directive.Ifnull
userdirective = Org.apache.velocity.tools.generic.directive.Ifnotnull
3. Use the null tool to determine
#if ($null. IsNull ($foo))
Note that this is especially useful, especially if you need this judgment as a judgment sentence, such as when I want you to judge whether a set is null or empty, you can only use this method:
$if ($null. IsNull ($mycoll) | | $mycoll. Size () ==0)
=========================================
1. Determine if velocity is null
Method one, #ifnull () or #ifnotnull ()
Eg: #ifnull ($XXX)
Warn: To use this feature, you must include the following in the Velocity.properties file:
Userdirective = Org.apache.velocity.tools.generic.directive.Ifnull
Userdirective = Org.apache.velocity.tools.generic.directive.Ifnotnull
Method Two, $null. IsNull ()
Eg: #if ($null. IsNull ())
It is recommended to use method two, especially when judging that the set object is null.
2. Determine if velocity is empty
Judge null: #if (! $xxx)
Judgment non-null: #if ($XXX)
3, for more detailed information, please refer to:
http://wiki.apache.org/velocity/velocitynullsupport
http://wiki.apache.org/velocity/checkingfornull