在脚本标签中使用 & 时出现 Thymeleaf 渲染错误 [英] Thymeleaf rendering error when using ampersand in script tag

查看:43
本文介绍了在脚本标签中使用 & 时出现 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.

这篇关于在脚本标签中使用 & 时出现 Thymeleaf 渲染错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆