【发布时间】:2020-06-13 15:52:40
【问题描述】:
我对 Thymeleaf 和 SpringBoot 还是有点陌生。
我一直在尝试使用 thymeleaf 片段将包含所有 javascript 映射的块注入页面 - dashboardAdmin.html。
我已经能够使用常规片段正确地注入带有块的片段,但是由于我必须注入多个脚本标签,这些标签不在 html 模板中的任何标签内,所以我无法使用常规方法.
我发现了一个类似的问题here 并遵循了提供的具体解决方案,但仍然没有成功,我已经添加了依赖项。也许有某种我不知道的语法错误。 由于我找不到太多关于此的参考资料,任何人都可以在这方面给我建议吗?
这是 fragment.html,其中包含要插入其他页面的所有模板
<body>
<th:block layout:fragment="script">
<script th:src="@{/vendor/login_v14/vendor/jquery/jquery-3.2.1.min.js}"></script>
<!-- Bootstrap 4 -->
<script th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>
<!-- jsGrid -->
<script th:src="@{/vendor/jsgrid/demos/db.js}"></script>
<script th:src="@{/vendor/jsgrid/jsgrid.min.js}"></script>
<!-- AdminLTE App -->
<script th:src="@{/js/main.js}"></script>
</th:block>
</body>
虽然这是我将块注入到的页面模板 - dashboardAdmin.html
<!DOCTYPE html>
<html lang="fr" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"
xmlns:layout="http://www.w3.org/1999/xhtml"
layout:decorate="~{fragments/fragments}">
<head th:replace="fragments/fragments :: head">
</head>
<body class="hold-transition sidebar-mini">
<!--js scripts-->
<th:block layout:fragment="script">
</th:block>
</body>
如果有人能告诉我我在这里做错了什么,将不胜感激:D!
【问题讨论】:
标签: spring-boot thymeleaf