thyemeleaf学习要点心得

一、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名称后的两个冒号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值