版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31653405/article/details/82665118
父页面:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<div class="layui-tab-content">
<div th:include="adminManagement/systemManagement/statistical::pagination"></div>
</div>
子页面:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<!--th:fragment="pagination" 放在哪个位置,则父页面就会调用哪个部分代码-->
<div th:fragment="pagination">
<div class="x-nav">
<span class="layui-breadcrumb">
<a href="">首页</a>
<a href="">统计分析</a>
<a> <cite>利润统计</cite></a>
</span>
</div>
</div>
讲解:
【参考: https://blog.csdn.net/believe__sss/article/details/79992408 】 ---- 感谢老师!!!
注意:第一个pagination为上述公共部分的文件名,第二个pagination为th:fragment的值。这样便可以解决公共部分代码的抽取。
fragment加载语法如下:
templatename::selector:”::”前面是模板文件名,后面是选择器
::selector:只写选择器,这里指fragment名称,则加载本页面对应的fragment
templatename:只写模板文件名,则加载整个页面
================== fragment语法 =============================
<!-- 语法说明 "::"前面是模板文件名,后面是选择器 -->
<div th:include="template/footer::copy"></div>
<!-- 只写选择器,这里指fragment名称,则加载本页面对应的fragment -->
<div th:include="::#thispage"></div>
<!-- 只写模板文件名,则加载整个页面 -->
<div th:include="template/footer"></div>
================= 加载块 ============================
<span id="thispage">
div in this page.
</span>
th:include 和 th:replace都是加载代码块内容,但是还是有所不同
th:include:加载模板的内容: 读取加载节点的内容(不含节点名称),替换div内容
th:replace:替换当前标签为模板中的标签,加载的节点会整个替换掉加载他的div
公共部分如下:
<!-- th:fragment 定义用于加载的块 -->
<span th:fragment="pagination">
the public pagination
</span>
引用时如下:
================= th:include 和 th:replace============================
<!-- 加载模板的内容: 读取加载节点的内容(不含节点名称),替换<div>的内容 -->
<div th:include="pagination::pagination">1</div>
<!-- 替换当前标签为模板中的标签: 加载的节点会整个替换掉加载他的<div> -->
<div th:replace="pagination::pagination">2</div>
结果如下:
<!-- 加载模板的内容: 读取加载节点的内容(不含节点名称),替换<div>的内容 -->
<div> the public pagination</div>
<!-- 替换当前标签为模板中的标签: 加载的节点会整个替换掉加载他的<div> -->
<span> the public pagination</span>
实例:
<div class="layui-tab-item layui-show" >
<div th:include="adminManagement/systemManagement/statistical::pagination"></div>
</div>
<body class="layui-anim layui-anim-up" th:fragment="pagination">
以上就是测试过的代码
--------------------------------------------------------------------------------------------------------------
以上是自己整理的,并测试过,可以直接用
----------------------------------------------------------------------------------------------------------------
转载声明:本文为博主原创文章,未经博主允许不得转载。
----------------------------------------------------------------------------------------------------------------
文章中,有问题,可以在评论区评论,一起探讨编程中奥秘!
----------------------------------------------------------------------------------------------------------------
来都来了,那就点个赞吧