java鬼混笔记:springboot之thymeleaf 5:模板引入与删除代码
2017-11-23 22:25
786 查看
记录模板引入,也就是别的html引入。
首先在/main/resources/templates下面创建一个footer.html,标签:th:fragment
内容如下:
接着在c.html中引入footer.html中的代码,使用方法如下
浏览器打开c.html后,看到效果
this is footer
from id
1 2
----------
this is footer
this is footer
---------------
删除代码,得用 th:remove
all 删除当前标签和其内容和子标签
body 不删除当前标签,但是删除其内容和子标签
tag 删除当前标签,但不删除子标签
all-but-first 删除除第一个子标签外的其他子标签
none 啥也不干
(直接拿别人翻译的)
首先在/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 啥也不干
(直接拿别人翻译的)
相关文章推荐
- java鬼混笔记:springboot之thymeleaf 6:内联模式
- java鬼混笔记:springboot之thymeleaf 2:字符串Strings常见的使用方法
- java鬼混笔记:springboot之thymeleaf 3:th:each遍历
- java鬼混笔记:springboot之thymeleaf 4:常见的格式化方法
- java鬼混笔记:springboot之thymeleaf 1:简单的thymeleaf例子
- java鬼混笔记:springboot 2、springboot修改访问端口
- java鬼混笔记:springboot 5、springboot的Scheduled定时器:fixedDelay和fixedRate区别
- springboot用thymeleaf模板的paginate分页完整代码
- 【学习笔记】spring boot + zookeeper + dubbo + rabbitMq + mysql + thymeleaf/freemarker + mybaits 代码试验
- java鬼混笔记:springboot 7、springboot整合mybatis后再加上druid数据库连接池
- java鬼混笔记:springboot 4、springboot热部署
- java鬼混笔记:springboot 3、springboot创建web项目和打包
- java鬼混笔记:springboot 6、springboot整合mybatis(支持多数源)
- 第十二章:SpringBoot_Web开发——(引入thymeleaf模板)
- java鬼混笔记:springboot 9、springboot整合mybatis加上分页功能
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板