Velocity学习--如何判断一个对象是否为空(null)

来源:互联网 发布:尚品宅配怎么样 知乎 编辑:程序博客网 时间:2024/06/05 16:21


http://blog.sina.com.cn/s/blog_c0f05f6c0101pii9.html


对于这种常用而记不住的知识还是要记录一下,以免每次都找人帮忙,那就不好了...
方法一:
 

         #if(!$test)  #end      如果对象为空
          #if($test)   #end      如果对象不为空
方法二:
          使用#ifnull() #end 和#ifnotnull()
          #ifnull($test)  #end   如果对象为空
          #ifnotnull($test)  #end 如果对象不为空
          需要注意的是:
  要使用这个特性必须在velocity.properties文件中加入:

userdirective =org.apache.velocity.tools.generic.directive.Ifnull
userdirective =org.apache.velocity.tools.generic.directive.Ifnotnull

方法三:

          #if($null.isNull($test))   在需要这个判断作为一个判断字句时,比如我要你判断一个集合为null或为空时只能使用这种方式了;

判断为空的方法:

         #if("" == $变量名) 或使用#if("" != $变量名)


0 0
原创粉丝点击