`

thymeleaf th:replace th:include th:insert 的区别

 
阅读更多

关于thymeleaf th:replace th:include th:insert 的区别

th:insert   :保留自己的主标签,保留th:fragment的主标签。

th:replace :不要自己的主标签,保留th:fragment的主标签。

th:include :保留自己的主标签,不要th:fragment的主标签。(官方3.0后不推荐)

 

 

需要替换的片段内容:
<footer th:fragment="copy">
   <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>
 
导入片段:
 
  <div th:insert="footer :: copy"></div>
 
  <div th:replace="footer :: copy"></div>
 
  <div th:include="footer :: copy"></div>
  
 
结果为:
 
<div>
    <footer>
       <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
    </footer>  
</div>  
 
<footer>
  <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</footer>  
 
<div>
  <script type="text/javascript" th:src="@{/plugins/jquery/jquery-3.0.2.js}"></script>
</div>  
 

 

 

分享到:
评论

相关推荐

    Thymeleaf中th:each及th:if使用方法解析

    本文将深入探讨Thymeleaf中的两个关键指令:`th:each` 和 `th:if`。 ### 一、th:each `th:each` 指令主要用于遍历数据集合,这些集合通常由控制器(Controller)传递到视图(View)。例如,以下是一个简单的控制器...

    thymeleaf实现th:each双重多重嵌套功能

    在本示例中,我们将探讨如何使用Thymeleaf的`th:each`指令来实现HTML模板中的双重或多重嵌套循环,以便动态加载一二级文章分类。Thymeleaf是一个强大的服务器端模板引擎,常用于Spring Boot项目,用于生成动态HTML...

    thymeleaf局部刷新解决方案.docx

    然而,在实际操作过程中,尤其是在尝试使用`th:replace`属性结合变量表达式来实现这一功能时,往往会遇到各种各样的错误,比如“找不到对应模板”等问题。 #### 解决方案 为了解决上述问题,本文将详细介绍一种...

    thymeleaf Examples: Layouts

    Thymeleaf Examples: Layouts This is an example project containing code used in the "Thymeleaf Layouts" tutorial. The project was created using Spring MVC 4 Quickstart Maven archetype: ...

    thymeleaf th fragment高级应用 – Pure nonsense.rar

    然后,我们可以通过`th:include`或`th:replace`指令来引用和插入Fragment。`th:include`会将Fragment内容嵌入到当前元素内部,而`th:replace`则会替换掉当前元素。例如: ```html &lt;div th:include="/fragments/...

    thymeleaf的th标签

    th:include th:include 标签用来布局标签,例如:&lt;head th:include="layout :: htmlhead" th:with="title='xx'"&gt;...&lt;/head&gt; th:replace th:replace 标签用来布局标签,例如:&lt;div th:replace="fragments/header :: ...

    thymeleaf-3.0.12.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-3.0.12.RELEASE.jar; 赠送原API文档:thymeleaf-3.0.12.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-3.0.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:thymeleaf-3.0.12.RELEASE.pom;...

    spring-boot-thymeleaf-sample.zip

    Thymeleaf高级语法:构建复杂表格 文章中所用到的代码实例,使用SpringBoot + Thymeleaf,构建复杂表格的实例代码。使用SpringBoot构建,包含后端代码和前端HTML模板

    Thymeleaf显示base64字符串为图片.docx

    在网页开发中,有时我们需要将Base64编码的字符串直接作为图片显示出来,这在Thymeleaf框架中可以通过特定的方式实现。Base64是一种数据编码方式,它将二进制数据转化为可打印的ASCII字符,常用于在HTTP协议中传输...

    thymeleaf语法入门

    本文档以Thymeleaf官方文档为基础,科学系统地、循序渐进地将Thymeleaf的使用方法、技术细节、扩展思路铺展开来,带您走进Thymeleaf的欢乐世界。

    thymeleafth常用标签

    - **说明**:此例中,定义了一个名为 `alert` 的片段,可以在其他地方通过 `th:include` 或 `th:replace` 引用来重用。 ##### 14. `th:include` - **功能介绍**:用于将一个片段的内容插入到另一个位置。 - **案例...

    thymeleaf参考手册

    12. **模板片段**:Thymeleaf允许定义和重用模板片段,通过`th:fragment`和`th:replace`或`th:include`实现。 13. **安全特性**:Thymeleaf有防止XSS攻击的内置机制,如自动转义输出,确保Web应用的安全。 这个...

    SpringBoot-thymeleaf模板集成

    SpringBoot-thymeleaf模板集成是现代Java Web开发中常用的一种技术组合,它结合了Spring Boot的便捷性和Thymeleaf模板引擎的强大功能。Spring Boot致力于简化Spring应用的初始搭建以及开发过程,而Thymeleaf则是一款...

    thymeleaf用法举例

    如果想要学习thymeleaf的小白同学,请下载下来看看吧,希望对你有所帮助

    thymeleaf_3.0.5_中文参考手册.pdf

    - 片段(Fragment)是可复用的HTML部分,可以通过`th:include`和`th:replace`引用。 9. 数据对象的转换和格式化 - Thymeleaf提供了一些内置的转换服务,例如日期和数字格式化。 - 用户可以自定义转换服务以满足...

    Thymeleaf_v3.0.5_参考手册(中文版).zip

    6. **片段(Fragment)**:Thymeleaf的片段功能允许重用模板代码,通过`th:replace`和`th:include`指令实现。 7. **条件注解(Conditional Attributes)**:Thymeleaf可以基于条件添加或移除HTML属性,如`th:attr`...

    Thymeleaf常用功能

    9. **注释处理**:Thymeleaf的`th:remove`属性可以控制元素是否被移除,`th:include`和`th:replace`用于模板的嵌入和替换。 10. **延迟计算**:Thymeleaf的`th:with`可以创建局部变量,进行延迟计算,提高模板的...

    idea+springboot+thymeleaf

    标题 "idea+springboot+thymeleaf" 暗示了这个压缩包可能包含一个使用IntelliJ IDEA开发的Spring Boot项目,其中整合了Thymeleaf模板引擎。让我们详细了解一下这三个关键组件: 1. **IntelliJ IDEA**:这是一款由...

    thymeleaf英文文档

    10. **模板布局**:Thymeleaf的布局系统允许创建可重用的头部、脚部和侧边栏,通过`th:replace`和`th:include`实现内容插入。 11. **Spring集成**:Thymeleaf与Spring框架有紧密集成,可以方便地与Spring Security...

    Thymeleaf实例程序

    Thymeleaf是一种现代的Java模板引擎,常用于构建Web应用程序的视图层,尤其在Spring MVC框架中应用广泛。这个实例程序旨在帮助开发者理解如何将Thymeleaf与Java Web项目集成,以及如何在实际开发中运用Thymeleaf的...

Global site tag (gtag.js) - Google Analytics