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

Fra*_*ama 6 java spring-mvc web thymeleaf

我想将谷歌地图javascript添加到Thymeleaf模板中,如下所示:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places
Run Code Online (Sandbox Code Playgroud)

它抛出了异常:

org.xml.sax.SAXParseException; lineNumber: 209; columnNumber: 93; The reference to entity "key" must end with the ';' delimiter
Run Code Online (Sandbox Code Playgroud)

我试图改变&&,但什么都没有改变.

对你的帮助表示感谢.谢谢!

Abo*_*odz 5

Thymeleaf使用XML解析器,并且该字符&被视为XML中的特殊字符。您必须将&其替换为XML对等符。您的&URL将为:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places
Run Code Online (Sandbox Code Playgroud)

在thymeleaf 3中,因为他们为thymeleaf编写了一个新的解析器,所以这不是问题。


san*_*uck 0

这是 Thymeleaf 中的一个错误,但自 2.1.4 以来已修复。

看看这个问题(这个问题描述的麻烦)。