Escaping quotes in velocity template

后端 未结 2 1106
情深已故
情深已故 2020-12-18 18:11

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, do

相关标签:
2条回答
  • 2020-12-18 18:53

    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.

    0 讨论(0)
  • 2020-12-18 19:07

    See the Velocity Escape Tool:

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

    0 讨论(0)
提交回复
热议问题