原文:https://blog.csdn.net/h1021456873/article/details/79085505

Thymeleaf html 导入(th:replace & th:include)

模板模块导入

首先定义一个/WEBINF/templates/footer.html文件:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"><body><div th:fragment="copy">&copy; 2011 The Good Thymes Virtual Grocery</div></body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

上面的代码定义了一个片段称为copy,我们可以很容易地使用th:include 或者 th:replace属性包含在我们的主页上:

<body>
...
<div th:include="footer :: copy"></div>
</body>
  • 1
  • 2
  • 3
  • 4

include的表达式想当简洁。这里有三种写法:

  • “templatename::domselector” 或者 “templatename::[domselector]”引入模板页面中的某个模块。
  • “templatename”引入模板页面。
  • “::domselector” 或者 “this::domselector” 引入自身模板的模块 
    上面所有的templatename和domselector的写法都支持表达式写法:
<div th:include="footer :: (${user.isAdmin}? #{footer.admin} : #{footer.normaluser})"></div>
  • 1

不使用th:fragment来引用模块

...
<div id="copy-section">
&copy; 2011 The Good Thymes Virtual Grocery
</div>
...

我们可以用css的选择器写法来引入

<body>
...
<div th:include="footer :: #copy-section"></div>
</body>

th:include 和 th:replace的区别

th:include和th:replace都可以引入模块,两者的区别在于 
th:include:引入子模块的children,依然保留父模块的tag。 
th:replace:引入子模块的所有,不保留父模块的tag。 
举个栗子:

<footer th:fragment="copy">
&copy; 2011 The Good Thymes Virtual Grocery
</footer>

引入界面:

<body>
...
<div th:include="footer :: copy"></div>
<div th:replace="footer :: copy"></div>
</body>

结果是:

<body>
...
<div>
&copy; 2011 The Good Thymes Virtual Grocery
</div>
<footer>
&copy; 2011 The Good Thymes Virtual Grocery
</footer>
</body>

th:replace th:include相关推荐

  1. boost::replace相关的测试程序

    boost::replace相关的测试程序 实现功能 C++实现代码 实现功能 boost::replace相关的测试程序 C++实现代码 #include <boost/range/algor ...

  2. boost::mpl模块实现replace相关的测试程序

    boost::mpl模块实现replace相关的测试程序 实现功能 C++实现代码 实现功能 boost::mpl模块实现replace相关的测试程序 C++实现代码 #include <boo ...

  3. boost::hana::replace用法的测试程序

    boost::hana::replace用法的测试程序 实现功能 C++实现代码 实现功能 boost::hana::replace用法的测试程序 C++实现代码 #include <boost ...

  4. c++stl和std_std :: replace()函数以及C ++ STL中的示例

    c++stl和std C ++ STL std :: replace()函数 (C++ STL std::replace() function) replace() function is a lib ...

  5. asp.net的cms 核心代码篇

    好像开源有点多余,核心代码就下面这些. 1 using System;2 using System.Collections;3 using System.Collections.Generic;4 u ...

  6. [译]Vulkan教程(04)基础代码

    [译]Vulkan教程(04)基础代码 General structure 通用结构 In the previous chapter you've created a Vulkan project w ...

  7. Thymeleaf 基本用法总结

    一.引用命名空间 <html xmlns:th="http://www.thymeleaf.org"> 在html中引入此命名空间,可避免编辑器出现html验证错误,虽 ...

  8. boost使用学习总结

    boost常用库案例 http://www.cnblogs.com/wangkangluo1/archive/2011/07/19/2110746.html 1.boost::any boost::a ...

  9. Thymeleaf抽取公共页面片段

    抽取页面 项目中,一般把所有的公共页面片段都抽取出来 放在一个独立的页面中 其他,所有的页面根据需要进行引用 参考文档 th:fragment 抽取公共元素 Name,随便自定义命名 <!DOC ...

最新文章

  1. 在JavaScript中逐个遍历数组?
  2. powerdesigner使用vba脚本创建物理模型的表和列
  3. Cisco2620路由器的密码恢复和灾难性恢复
  4. 给部署在openshift上的WordPress添加wptouch插件
  5. Android手游《》斗地主完整的源代码(支持单机和网络对战)
  6. 树上倍增求LCA详解
  7. Repeater的使用
  8. [转载] python通过adb获取android手机耗电量
  9. 调色插件怎么安装_修图调色一键搞定!PS大师级调色插件NikCollection 八合一送你...
  10. Java基础---数组内容详解
  11. Python+pywin32批量转换Word文件为PDF文件
  12. activemq mysql 配置详解_activeMQ数据库配置
  13. 使用Infopath时要注意的有哪些
  14. 区块链技术指南:术语
  15. Linux部署-elasticsearch7.6.1
  16. 本学期关于Android学习的总结
  17. 富爸爸穷爸爸--读书笔记
  18. 题目 1902: 九宫格
  19. 2015年秋季腾讯校园招聘开发岗笔试题(四道大题)
  20. Thread线程中的stop方法过时问题

热门文章

  1. 微信App支付相关问题
  2. BLE中GATT介绍
  3. 浅谈html5的发展与现状摘要,浅谈HTML5的发展与现状(最标准格式论文)
  4. “蝙蝠”关系学(上):“蝙蝠”…
  5. 随机头像大全,多分类带历史记录微信小程序源码下载支持流量主
  6. 孙悟空,.NET和Web争霸
  7. Django实战技巧(2)-git代码仓分支管理技巧
  8. swagger python自动化用例_swagger 自动生成接口测试用例
  9. 如何让企业督办管理系统对接第三方应用
  10. slickedit字体设置——使用 Verdana 字体