我的thymeleaf学习笔记

一、常用语法

1.th:text 替换文本

<p th:text="${x.a}">被替换文本</p>

2.字符串拼接

<p th:text="${'拼接块'+x.a+'拼接块'+x.b+'拼接块'}" >被替换文本</p>

3.遍历List

<tr th:each="x:${xList}">
   <th th:text="${x.a}">被替换文本</th>
   <th th:text="${x.b+' '+x.c}" >被替换文本</th>
</tr>

4.格式化日期

th:text="${#dates.format(x.y, 'yyyy-MM-dd HH:mm:ss')}"

 

二、引入外部文件:

1.@{}的方式引入外部文件会包含项目名

css:    th:href="@{/css/***.css}"
js:     th:src="@{/js/***.js}"
img:    th:src="@{/img/***.png}"

2.include引入文件

(1)模板文件引入layout,并且声明decorator=“自定义X”

 

<html xmlns:th="http://www.thymeleaf.org" 
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
layout:decorator="web-model">

(2)模板文件写入内容,th:fragment=“自定义Y”。ps:th:remove=“tag”为了删掉外边包围着的div

 

<div th:fragment="left" th:remove="tag">
 ***模板内容***
</div>

(3)需要引入的模板文件的html

 

 <div th:include="web-model(自定义X)::left(自定义Y)" ></div>

(4)结果

 

“<div th:include="web-model(即自定义X)::left(即自定义Y)" ></div>”   替换成   “***模板内容***”

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值