逃避美元符号的速度

Har*_*iec 2 java string parameters velocity

我在速度模板文件中有这样一个字符串:

<a id="superurl_${getItemid()}" href="http://example.com?$param1=345&$param2=abf&param3=${par3}">link1</a>
Run Code Online (Sandbox Code Playgroud)

这就是

<a id="superurl_1288" href="http://example.com?$param1=345&$param2=abf&param3=${par3}">link1</a>
Run Code Online (Sandbox Code Playgroud)

但是,它应该呈现为

<a id="superurl_1288" href="http://example.com?$param1=345&$param2=abf&param3=zzz">link1</a>
Run Code Online (Sandbox Code Playgroud)

如何修改源以${par3}使其由其值呈现并且不被视为字符串的一部分?

Cre*_*mbo 5

您可以使用#[[ .. ]]#在Velocity中转义字符串.我认为在你的情况下,前面的$可能与他们之后发生的事情相冲突.请尝试以下方法:

<a id="superurl_${getItemid()}" href="#[[http://example.com$param1=345&$param2=abf&param3=]]#${par3}">link1</a>
Run Code Online (Sandbox Code Playgroud)

另外,请确保实际传递名为"par3"的变量.(这更可能是它没有被解析的原因?)