Jor*_*.S. 25 java templates velocity
在速度我有一个变量,其值为null.在这种情况下,我不想显示任何内容.
目前模板引擎将""转换为null,所以我必须这样做.
#set ( $a = "")
#if ($a)
assert("never prints a neither gets here: " + $a)
#end
Run Code Online (Sandbox Code Playgroud)
有没有办法直接做到这一点?我希望能够做出类似的事情:
This is the variable $a. ## in case that $a is null i don't want 'dollar a' to be displayed
Run Code Online (Sandbox Code Playgroud)
Den*_*isS 19
这是你的例子:
This is the variable $!a.
Run Code Online (Sandbox Code Playgroud)
如果$ a为null或"",则Velocity将呈现:
This is the variable .
Run Code Online (Sandbox Code Playgroud)
官方指南部分:https: //velocity.apache.org/engine/devel/user-guide.html#quietreferencenotation
| 归档时间: |
|
| 查看次数: |
40983 次 |
| 最近记录: |