Spring Boot Tymeleaf常用标签写法

Spring Boot Tymeleaf常用标签写法

一、链接形式

1、引入文件

link
<link th:href="@{/css/index.css}" rel="stylesheet" >

引入css

a标签
<a th:href="@{/content/{id}(id=${user.id})}"

此处为带参路径,其中content为固定路径,id为参数,user.id为对参数取值并赋给路径拼接参数id

img的src
<img th:src="@{/images/paper_blank.png}"> 

二、普通取值

th:text
<span th:text="${userName}"></span>

userName为存入的参数名

<span th:text="${user.userName}"></span>

user为存入的对象,userName为user的属性

th:utext 原样输出

此处区别一下th:text和th:utext 由两短代码输出结果说明

th:text="${op.opType}+'、'+${op.opContent}+'<br>'"

网页显示结果为 A、72<br>B、99<br>

th:text="${op.opType}+'、'+${op.opContent}+'<br>'"

网页显示结果为

A、72
B、99

很明显的
换行符此时生效了

三、循环

ul li
<ul th:each="user,v:${users}">
	<li th:text="${user.userName}">
	<li th:text="${v.index}">
</ul>

users为list集合 循环取出对象为user
v是计数对象
此处 v.index 下标 (如第一个为0)
v.count 计数(如第一个为1)

table tr td

<table>
	<tr th:each="user,v:${users}">
		<td th:text="${user.userName}"></td>
		<td th:text="${v.index}"></td>
	</tr>
</table>

循环嵌套

<ul th:each={users,v:${userslist}>
	<ul th:each={user,u:${users}>
		<li th:text="${user.userName}"></li>
	</ul>
</ul>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值