Thymeleaf:包含js文件并包装到<! - [CDATA块

时间:2017-02-15 14:35:34

标签: thymeleaf

Thymeleaf:如何包含javascript文件( 此文件的内容)并使用CDATA块包装此文件的内容 我的js文件是这样的:

this is javascript file and have &&, I cannot edit this file

在我的百里叶模板中,我有:

<script th:include="http://address-to-file/myfile.js"></script>

我想要包含此文件,但我有错误: org.xml.sax.SAXParseException:实体名称必须紧跟'&amp;'在实体参考中。

如何将此包含文件包装到CDATA块?在我的模板中,我实现了这个结果:

/*<![CDATA[*/    
this is javascript file and have &&, I cannot edit this file
/*]]>*/

1 个答案:

答案 0 :(得分:0)

您可以像这样使用 th:src

<script th:src="@{//address-to-your-file/yourfile.js";}"></script>

...将呈现未经修改的(URL重写除外),例如:

<script src="address-to-your-file/yourfile.js"></script>
相关问题