thymleaf ——页面之前的引入、传值

一、参考资料

thymleaf官方文档模块布局

二、实际测试栗子(文档中都有,只列举一个栗子)

片段定义

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">

  <body>
  
    <div th:fragment="copy">
      &copy; 2011 The Good Thymes Virtual Grocery
    </div>
  
  </body>
  
</html>

 引入定义

<body>

  ...

  <div th:insert="~{footer :: copy}"></div>
  
</body>

这里有个小细节:

       th:insert="~{footer :: copy}"中的footer,如果文件不同级,需要写详细路径,如:th:insert="~{view/footer :: copy}";

三、传值问题

定义片段中接收变量和传值

片段1:

<div th:fragment="frag (onevar,twovar)">
    <p th:text="${onevar} + ' - ' + ${twovar}">...</p>
</div>

引入传值页1:

<!-- 无需纠结是replace还是include、insert -->
<div th:replace="::frag (${value1},${value2})">...</div>

当片段中未定义有关形参时:

片段2:

<aside class="main-sidebar">
    <span th:text="${tree == 'index'}?'6666':'9999'"></span>
	<span th:text="${treemenu}"></span>
</aside>

引入传值页面2:

<aside th:include="~{view/sidebar}" th:with="tree=${'index'},treemenu=${'overView'}"></aside>

使用的th:with标签携带数据

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值