Escaping quotes in velocity template

拟墨画扇 提交于 2019-11-28 02:48:49

问题


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?


回答1:


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:

$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.




回答2:


See the Velocity Escape Tool:

https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html



来源:https://stackoverflow.com/questions/19579748/escaping-quotes-in-velocity-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!