在脚本标签中使用 & 时出现 Thymeleaf 渲染错误

在脚本标签中使用 & 时出现 Thymeleaf 渲染错误

问题描述:

我想将 google map javascript 添加到 Thymeleaf 模板,如下所示:

I want to add google map javascript to a Thymeleaf template, like this:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places

它抛出异常:

org.xml.sax.SAXParseException; lineNumber: 209; columnNumber: 93; The reference to entity "key" must end with the ';' delimiter

我尝试将 & 更改为 & 但没有任何改变.

I tried to change & to & but nothing changed.

您的帮助将不胜感激.谢谢!

Your help will be greatly appreciated. Thanks!

Thymeleaf 使用 XML 解析器,字符 & 被认为是 XML 中的特殊字符.您必须将 & 替换为其 XML 等价的 &.您的 URL 将是:

Thymeleaf uses XML parser, and the character & is considered a special character in XML. You have to replace & with its XML equvilant &.Your URL will be:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places

在 thymeleaf 3 中,这不会成为问题,因为他们为 thymeleaf 编写了一个新的解析器.

In thymeleaf 3, it won't be a problem since they wrote a new parser for thymeleaf.