java 我如何隐藏空的 Velocity 变量名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:45:55  来源:igfitidea点击:

How I hide empty Velocity variable names?

javatemplatesstrutsvelocity

提问by Fernando Barrocal

I am using Struts + Velocity in a Java application, but after I submit a form, the confirmation page (Velocity template) shows the variable names instead an empty label, like the Age in following example:

我在 Java 应用程序中使用 Struts + Velocity,但在我提交表单后,确认页面(Velocity 模板)显示变量名称而不是空标签,如下例中的 Age:

Name: Fernando

Age: {person.age}

Sex: Male

姓名:费尔南多

年龄:{person.age}

性别:男

I would like to know how to hide it!

我想知道怎么隐藏!

回答by Jason Sparks

You can mark variables as "silent" like this:

您可以像这样将变量标记为“ silent”:

$!variable

If $variable is null, nothing will be rendered. If it is not null, its value will render as it normally would.

如果 $variable 为 null,则不会呈现任何内容。如果它不为空,它的值将像往常一样呈现。

回答by Nathan Bubna

You will also need to be sure and use the proper syntax. Your example is missing the dollar before the variable. It should be $!{person.age}, not just {person.age}.

您还需要确保并使用正确的语法。您的示例在变量之前缺少美元。它应该是 $!{person.age},而不仅仅是 {person.age}。