原文: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. PHP 两个页面跳转,session会失效?
  2. Bitmap recycle()
  3. 教你玩转CSS Position(定位)
  4. 2 小时学会 springboot ( 附实例讲解 )
  5. java实验_Java实验报告(实验一)
  6. 源码包安装mysql5.7.25_centos源码安装mysql5.7.25-boost
  7. 如何评价周志华深度森林模型
  8. 背景图的属性(backgroud)
  9. 24期分期免息可以提前还吗?
  10. gerp命令基础介绍
  11. Java进阶:SpringMVC中通过监听器将Spring上下文对象放置到servletContext中,方便其他地方使用
  12. 技术人的充电时刻,200分钟QA交流,尽在SDCC 2017·深圳站
  13. 机器学习和深度学习有什么区别?
  14. php输出甲子年,甲子年是哪一年?甲子年生人今年多大?
  15. 常见损失函数 损失函数选择方法
  16. 【个人研究】21世纪西方运用脑电(EEG)的音乐研究动向分析(一)
  17. 2015年西安小升初奥数培训班奥数老师(排名排行)龙虎英雄榜
  18. 数据标注去哪接任务订单?靠谱的数据标注平台有哪些?
  19. 类的不同实例化使用一张虚函数表
  20. 你有一条微信未发送_微信支持发送大文件;男子薅90年爱奇艺VIP;京东方再次未通过苹果质量审查...

热门文章

  1. 以九宫格为例谈声明式语言Prolog
  2. 超简单利用java实现小游戏剪刀石头布
  3. 说说Web 无障碍设计
  4. Django实战技巧(2)-git代码仓分支管理技巧
  5. geojson mysql存储_mongodb存储geoJson
  6. matlab中的nextpow2函数
  7. Java 根据开始日期和结束日期,获取日期之间的工作日,去除了周末和法定节假日
  8. MATLAB与C/C++混合编程之MATLAB调用C程序
  9. iptables防火墙之SNAT与DNAT
  10. AIX 热添加FcOE卡