VTL 中的美元和感叹号 (bang) 符号

Dollar and exclamation mark (bang) symbols in VTL

我最近在一些 Velocity 代码中遇到了这两个变量:

$!variable1
!$variable2

我对它们的相似性感到惊讶,所以我开始怀疑代码的正确性,并对找出两者之间的区别产生了兴趣。

velocity 是否允许这两个符号的任意顺序或它们有不同的用途?你知道答案吗?

我在 google 和 Whosebug 上搜索了很多次,然后终于在 people.apache.org 找到了答案。

据此:

It is very easy to confuse the quiet reference notation with the boolean not-Operator. Using the not-Operator, you use !${foo}, while the quiet reference notation is $!{foo}. And yes, you will end up sometimes with !$!{foo}...

毕竟很简单,遗憾的是它没有立即打动我。希望这对某人有所帮助。

@Jr.这是我在进行 VM 研发时遵循的指南:http://velocity.apache.org/engine/1.7/user-guide.html

Velocity 使用 !$ 和 $!不同事物的注释。如果你使用 !$ 它基本上和普通的 "!" 一样。运算符,但是 $!用作基本检查以查看变量是否为空,如果是,则将其打印为空字符串。如果您的变量为空或 null 并且您不使用 $!注释它将实际变量名称打印为字符串。