Java 在速度模板中转义引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19579748/
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
Escaping quotes in velocity template
提问by Krishna Sarma
I have a java method, that takes a few strings. This method needs to be called from a Velocity Template. However, the strings are too complex, with lots of single quotes, double quotes and commas as well. As a result merge is failing. Is there a way to escape quotes in Velocity?
我有一个 java 方法,它需要几个字符串。此方法需要从速度模板调用。但是,字符串太复杂,单引号、双引号和逗号也很多。结果合并失败。有没有办法在 Velocity 中转义引号?
采纳答案by Sergiu Dumitriu
It depends on which version of Velocity you're using. Velocity 1.7 has clear rules for escaping quotes: just double the same type of quotes used to wrap the string:
这取决于您使用的 Velocity 版本。Velocity 1.7 对转义引号有明确的规则:只需将用于包装字符串的相同类型的引号加倍:
$object.callMethod('Let''s have fun with "quotes"',
"Let's have fun with ""quotes""")
Prior to that, there were some fuzzy rules with backslash escapes that didn't always work as expected.
在此之前,有一些带有反斜杠转义的模糊规则并不总是按预期工作。