Velocity判斷null和空

2021-08-31 20:34:55 字數 508 閱讀 1311

velocity

apache

1、判斷velocity 是否為null

方法一 、 #ifnull() 或 #ifnotnull()

eg: #ifnull ($***)

warn:要使用這個特性必須在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時,灰常有用。

2、判斷velocity是否為空

判斷空:#if (! $***)

判斷非空: #if ($***)

3、更詳細的介紹請參考:

velocity判斷空和null

判斷是否為null有下面幾種方法 1.if foo 判斷 foo為空,判斷非空為 if foo 2.使用 ifnull 或 ifnotnull ifnull foo 要使用這個特性必須在velocity.properties檔案中加入 userdirective org.apache.velocit...

Velocity判斷null跟空

velocity判斷null和空 velocityapache 1 判斷velocity 是否為null 方法一 ifnull 或 ifnotnull eg ifnull warn 要使用這個特性必須在velocity.properties 檔案中加入 userdirective org.apach...

Velocity中如何判斷null

相信這個問題是很多使用velocity的朋友所經常碰到的,大家可能非常期望下面這樣的 能夠執行 if foo null end 實際上這段 會報錯。這是因為velocity中對null的支援比較特別。上說,判斷是否為null有下面幾種方法 1.if foo 判斷 foo為空,判斷非空為 if foo...