【SpringBoot学习】02-th:replace与th:insert详解

声明公共代码片段

通过th:fragment

  <div th:fragment="header_common">

    <p>这是fragment公共片段</p>
    
   </div>

通过id声明代码片段

   <div id="header_common_id">

      <p>这是id公共片段</p>

   </div>

替换/插入

使用th:replace 通过th:fragment

<div th:replace="header :: header_common"></div>

使用th:replace 通过id

 <div th:replace="header :: #header_common_id"></div>

使用th:insert 通过id

<h2  th:insert="header :: #header_common_id"></h2>

th:replace与th:insert区别

th:insert 和 th:replace都可以引入片段
两者的区别在于:
th:insert: 保留引入时使用的标签
th:replace:不保留引入时使用的标签,直接覆盖当前引用的标签

实操

在这里插入图片描述

可以使用id的方法

在这里插入图片描述

根据不同的场景使用不同的id内容 实现动态改变页面某一属性

在这里插入图片描述

头部使用公共代码

在这里插入图片描述

通过activeUri 的 id 和配置公共区域代码的 id 进行比对 来确定 id 后的值 从而动态实现不同的样式

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值