Velocity nulls和空字符串 [英] Velocity nulls and empty strings

查看:140
本文介绍了Velocity nulls和空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在速度中,我有一个变量,其值为 null 。在这种情况下,我不想显示任何内容。

In velocity I have a variable which its value is null. I don't want to display anything in that case.

目前模板引擎会将转换为 null ,所以我必须这样做。

Currently the template engine translates "" to null so I have to do.

#set ( $a = "")
#if ($a) 
   assert("never prints a neither gets here: " + $a)
#end

有没有办法我可以直接这样做吗?我希望能够做出类似的结果:

Is there a way I could do that directly? I'd like to be able to make something like:

This is the variable $a. ## in case that $a is null i don't want 'dollar a' to be displayed


推荐答案

$!a诀窍。您可以直接使用此表单而无需检查。

$!a does the trick. You can use this form directly without an if check.

这篇关于Velocity nulls和空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆