Iwo*_*ski 24
根据文档,如果你有这种情况:
<div th:include="..."> content here </div>
Run Code Online (Sandbox Code Playgroud)
片段将放在<div>标签内.
但是当你使用替换时:
<div th:replace="..."> content here </div>
Run Code Online (Sandbox Code Playgroud)
然后<div>将被内容取代.
Thymeleaf可以将其他页面的一部分作为片段(而JSP仅包括完整页面)使用th:include(将片段的内容包含到其宿主标签中)或th:replace(实际上将用片段替换宿主标签).
尝试用这个来理解假设这是片段
<div th:fragment="targetFragmentToIncludeInOurPage" id="tagWithFragmentAttribute">
<div id="contentGoesHere"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我们在这些 div 中使用它
<div id="tagWithReplaceAttribute" th:replace="fragments/header :: targetFragmentToIncludeInOurPage"></div>
<div id="tagWithInsertAttribute" th:insert="fragments/header :: targetFragmentToIncludeInOurPage"></div>
<div id="tagWithIncludeAttribute" th:include="fragments/header :: targetFragmentToIncludeInOurPage"></div>
Run Code Online (Sandbox Code Playgroud)
所以最终输出:
<div id="tagWithFragmentAttribute">
<div id="contentGoesHere"></div>
</div>
<div id="tagWithInsertAttribute">
<div id="tagWithFragmentAttribute">
<div id="contentGoesHere"></div>
</div>
</div>
<div id="tagWithIncludeAttribute">
<div id="contentGoesHere"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16974 次 |
| 最近记录: |