Thymeleaf 中如何实现including
Problem:Jsp中有including,Thymeleaf中有无类似的语法?
Solution:有,Themeleaf中提供同样功能的标签是 th:fragment="blockName" 和 th:replace="fileName::blockName"
Steps:
1.在共通网页common.html中定义通用块:
<!-- 标题栏 --> <div class="navbar" th:fragment="topNavbar"> <div class="navbar-inner"> <ul class="nav pull-right"></ul> <a class="brand" href="index.html"><span class="first">A股</span> <span class="second">Master</span></a> </div> </div>
2.在功能网页中引入通用块:
<!-- 标题栏 --> <div class="navbar" th:replace="common::topNavbar"></div>
实现了这两个步骤后,标题栏在common.html中书写和维护就行了,其它页面无需变更用就行了。
--2020年5月3日--