thymeleaf中简单运用-判断,遍历,链接拼接,模板提取公共页面

thymeleaf头文件

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

赋值

//会替换原来的值
<h1 th:text="aaa">123</h1>
//取model中msg的值
<h1 th:text="${msg}">123</h1>
<input th:value="${msg}">

判断

//判断优先级高,先判断后生成(判断msg中是否为空)
<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>

遍历

遍历1-5

<a th:each="i:${#numbers.sequence(1,5)}" th:text="${i}"></a>

遍历集合

<p th:each="user:${list}" th:text="${user}"></p>

链接拼接

<img th:src="@{/img/research/{filename}(filename=${research.filename})}">
<a th:href="@{/user/pwd/}+${user.userCode}">

模板提取公共页面

<!--需要提取的公共页面上加上th:fragment+片段名 -->
<p th:fragment="hello">hello world</p>

<!--使用公共片段,公共页面名称(如果放在包下需要路径名)::片段名(也支持选择器) -->

替换,效果,当前标签被替换成公共片段
<div th:replace="common :: head"></div>

插入,效果:将公共片段插入到当前标签中,片段会被当前标签包裹
<div th:replace="common :: head"></div>

包含,效果:引入公共片段中内容,会将片段内容直接放在当前标签中
<div th:include="common :: head"></div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值