java鬼混笔记:springboot之thymeleaf 5:模板引入与删除代码
来源:互联网 发布:淘宝众筹有什么条件 编辑:程序博客网 时间:2024/04/30 03:02
记录模板引入,也就是别的html引入。
首先在/main/resources/templates下面创建一个footer.html,标签:th:fragment
内容如下:
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8" /><title>Hello Thymeleaf!</title></head><body><div th:fragment="footer" class="xxxxxx"><!--其中fragment='footer'相当于引入的标识符-->this is footer</div> <div id="id"><!--通过id来引用这段代码-->from id</div> <div th:fragment="arg(one,two)"><!--可能传参,然后使用--><span th:text="${one}"/><span th:text="${two}"/></div> </body></html>
接着在c.html中引入footer.html中的代码,使用方法如下
<!DOCTYPE html><html xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8" /><title>Hello Thymeleaf!</title></head><body><!-- 通过fragment标识符引入,其中第一个footer是footer.html的文件footer,第二个footer是在footer.html代码中的th:fragment="footer"的footer,意思是引入这块的代码 --><div th:replace="footer :: footer"></div><!-- 通过id标识符引入 --><div th:replace="footer :: #id"></div><!-- 带参数引入 --><div th:replace="footer :: arg(1,2)"></div>----------<!-- insert直接引入包含html的内容,最终效果如下:<div th:insert="footer :: footer">this is footer(原来footer下面内容)</div> --><div th:insert="footer :: footer"></div><!-- replace:把footer的html代码拿过来显示最终效果如下:<div class="xxxxxx"> this is footer </div> 原来的<div th:replace="footer :: footer"></div>被替换 --> <div th:replace="footer :: footer"></div><!-- 官网不建议使用直接引入内容,最终效果如下:<div> this is footer </div> --> <div th:include="footer :: footer"></div></body></html>
浏览器打开c.html后,看到效果
this is footer
from id
1 2
----------
this is footer
this is footer
---------------
删除代码,得用 th:remove
<div id="id1" th:remove="all"><div id="id2">sfsfsfsf</div></div>th:remove有多个输入:分别如下
all 删除当前标签和其内容和子标签
body 不删除当前标签,但是删除其内容和子标签
tag 删除当前标签,但不删除子标签
all-but-first 删除除第一个子标签外的其他子标签
none 啥也不干
(直接拿别人翻译的)
阅读全文
0 0
- java鬼混笔记:springboot之thymeleaf 5:模板引入与删除代码
- java鬼混笔记:springboot之thymeleaf 3:th:each遍历
- java鬼混笔记:springboot之thymeleaf 6:内联模式
- java鬼混笔记:springboot之thymeleaf 1:简单的thymeleaf例子
- java鬼混笔记:springboot之thymeleaf 2:字符串Strings常见的使用方法
- java鬼混笔记:springboot之thymeleaf 4:常见的格式化方法
- java鬼混笔记:springboot之redis保存对象
- springboot之模板引擎 --- thymeleaf
- java springboot Thymeleaf模板引擎
- java鬼混笔记:springboot 5、springboot的Scheduled定时器:fixedDelay和fixedRate区别
- java鬼混笔记:springboot 1、第一个springboot项目例子
- java鬼混笔记:springboot 2、springboot修改访问端口
- java鬼混笔记:springboot 4、springboot热部署
- java鬼混笔记:springboot 8、springboot发邮件mail
- springboot之thymeleaf模板引擎章节
- SpringBoot Thymeleaf 模板引擎
- SpringBoot-thymeleaf模板集成
- springboot整合thymeleaf模板
- 周中训练笔记18
- python中self的一些浅显认识
- 结构体知识总结
- 【Github学习笔记】安装git,创建库,添加远程仓库,添加删除文件
- eclipse 搭建activiti5 项目生成流程过程
- java鬼混笔记:springboot之thymeleaf 5:模板引入与删除代码
- 标准模板库 STL-2 编程题#3:Set(Coursera 程序设计与算法 专项课程3 C++程序设计;执行输入的命令和数据)
- 下载MySQL历史版本
- 对tableView的contentOffset的理解
- 安装redis详情
- 魔女回忆副本脚本
- hive hdfs
- Docker简介
- 决策树、CART、GBDT、Xgboost学习笔记