Java 在脚本标记中使用符号AND时出现Thymeleaf呈现错误
我想将google map javascript添加到Thymeleaf模板中,如下所示:Java 在脚本标记中使用符号AND时出现Thymeleaf呈现错误,java,spring-mvc,web,thymeleaf,Java,Spring Mvc,Web,Thymeleaf,我想将google map javascript添加到Thymeleaf模板中,如下所示: 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
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
我试图将&
更改为&代码>但没有更改
非常感谢你的帮助。谢谢 这是Thymeleaf中的一个bug,但从2.1.4开始就被修复了
看看这个。
(中描述的故障)。Thymeleaf使用XML解析器,字符&
被认为是XML中的特殊字符。您必须将&
替换为它的XML对等&代码>。您的URL将是:
https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places
在thymeleaf 3中,这不会是一个问题,因为他们为thymeleaf编写了一个新的解析器。您有一些选择:
1) 根本不要使用th:src
2) 由于URL是绝对的,因此可以使用静态方法将其添加到服务器端:
<script th:src="${@urlService.getMapsUrl()}">...</script>
。。。
3) 使用一个
不确定该问题是否已在Thymeleaf 3中得到纠正,但它可能值得快速升级并查看。因为Thymeleaf模板是XML,您应该使用&
而不是属性值中的&
。您必须将&code>编码为&;。因为&;是&的转义序列,XML将以文本形式找到它。谢谢您的回答,@sanluck!事实上,我使用的是2.1.4版本,但问题仍然存在。比如:有什么问题吗?我想它一定是这样:
请注意。我发布了错误的URL,它一定是
它引发了这样一个异常org.thymeleaf.exceptions.TemplateProcessingException:无法解析为表达式:”@{https://maps.googleapis.com/maps/api/js(v=3.exp,key=xxx,libraries=plac锿)}"
Hi@Aboodz,我试过了,但对我不起作用……谢谢你的帮助answer@Aboodz,在本例中,弹簧返回400。所需参数“someParam”不存在。