我正在使用Spring Boot / MVC并学习Thymeleaf。
假设我的脚本位于另一台服务器上。
https://staticserver.com/main.js
我已将{/"//staticserver.com“部分添加为模型jsLocation
。
我想在以下方面做些事情:
<script src="${jsLocation}/main.js"></script>
这将呈现
<script src="//staticserver.com/main.js"></script>
答案 0 :(得分:3)
<script th:src="|${jsLocation}/main.js|"></script>
答案 1 :(得分:2)
您可以包含如下所示的外部js文件:
<script th:src="source to your external JS"></script>
由于查询也与模型有关,因此可以在下面的线程中获取更多详细信息。
Thymeleaf external javascript file shares the module attributes with html file