一、thymeleaf模板子页面引用JS,CSS,HTML的方法:
这是我的目录结构
1,引用JS文件
首先将公共资源提取出来放在单独的一个html中,并加入thymeleaf模板的引用
然后,在<div>中引用thymeleaf的th:fragment=“自定义一个名称” 标签,<script th:src="@{公共资源JS路径}">。
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="onload_js">
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/amazeui.min.js}"></script>
<script th:src="@{/js/app.js}"></script>
</div>
</body>
</html>
子页面中调用的方法,首先加入thymeleaf模板的引用
然后,自定义一个<div>,在<div>中引用thymeleaf的th:include=“公共资源的路径/html名称::自定义的js名称” 标签,(注意html名称后的两个冒号)
2,引用CSS文件
首先将公共资源提取出来放在单独的一个html中,并加入thymeleaf模板的引用
然后,在<head>中引用thymeleaf的th:fragment=“自定义一个名称(title)” 标签,<title th:text="${title}">,<link th:href="@{公共资源CSS路径}" rel="stylesheet" />。
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="commonHeader(title)">
<title th:text="${title}"></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link th:href="@{/i/favicon.png}" rel="icon" type="image/png"/>
<link th:href="@{/i/app-icon72x72@2x.png}" rel="apple-touch-icon-precomposed"/>
<link th:href="@{/css/amazeui.min.css}" rel="stylesheet" />
<link th:href="@{/css/admin.css}" rel="stylesheet" />
</head>
</html>
子页面中调用的方法,首先加入thymeleaf模板的引用
然后,自定义一个<head>,在<head>中引用thymeleaf的th:include=“公共资源的路径/html名称::自定义的css名称(标题)” 标签,(注意html名称后的两个冒号)
3,引用html文件
首先将公共资源提取出来放在单独的一个html中,并加入thymeleaf模板的引用
然后,在<div>中引用thymeleaf的th:fragment=“自定义一个名称” 标签。
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<div th:fragment="table">
<table>
<tr>
<th>标题</th>
</tr>
<tr>
<td>序号</td>
<td>名称</td>
<td>操作</td>
</tr>
</table>
</div>
</html>
子页面中调用的方法,首先加入thymeleaf模板的引用
然后,自定义一个<div>,在<div>中引用thymeleaf的th:replace=“公共资源的路径/html名称::自定义的div名称” 标签,(注意html名称后的两个冒号)