thymeleaf常用标签

th:id:替换id。

<input th:id="'name"/>

th:text:显示文本,可进行简单的计算。

<td  th:text="${name}">mlm</td> 
<td  th:text="1+1">2018</td>

th:utext:支持html的文本替换。

<span th:utext="${html}">content</span>

th:if:条件判断,可以多条件 and,or(二元操作符),!,not非(一元操作符)。

<div th:if="${user} != null">show</div>
<div th:if="${user} != null and ${user2} != null">hide</div> 

th:object:表单数据对象绑定,后台controller中参数保持一致,和选择(星号)表达式。

<div th:object="${user.name}"><div

th:value:属性赋值。

<option th:value="${user.name}"></option>

th:with:变量赋值运算。

<div th:with="result = ${user.count}%2 == 0"></div>

th:style:设置样式。

<div th:style="display:none"></div>

th:onclick:点击事件。

<td th:onclick = "'doOnclick()'"></td>

th:each:遍历集合中的对象。

<tr th:each="user,userStat:${users.list}">    
	<td th:text="${user.name}"></td>   
	 <td th:text="userStat.index"></td>
 </tr>

th:unless:判断条件,与th:if作用相反。

<div th:unless="${user} == null">show</div>

th:href:定义超链接,相当于标签中的href属性。

<a th:href="@{/send}" >Send</a>

th:switch th:case:多选一时多个同等级相同目的判断。

<div th:switch="${user.name}">    
    <p th:case="jack">first</p>
    <p th:case="${user2.name}">second</p>
</div>

th:include:布局标签,替换内容到引入的文件。

<head th:include="layout ::firstLayout" ></head>

th:replace:布局标签,替换整个标签到引入的文件。

<div th:replace="layout/header :: title"></div>

th:selected:选择框设置选中值,通常和th:each一起使用。

<select>    
	<option th:selected="${user.name} == ${otherUser.name}"></option> 
</select>

th:src:图片类地址引入。

<img  th:src="@{/img/pic.png}" />

th:inline:定义js脚本可以使用变量。

<script type="text/javascript" th:inline="javascript">

th:action:定义后台控制器的路径,表单的提交地址,相当于标签的action属性。

<form th:action="@{user/login}" method="post"></form>

th:remove:删除某个属性。

<!--
1.all:删除包含标签和所有的孩子。
2.body:不包含标记删除,但删除其所有的孩子。
3.tag:包含标记的删除,但不删除它的孩子。
4.all-but-first:删除所有包含标签的孩子,除了第一个。
5.none:什么也不做。这个值是有用的动态评估。
-->
<tr th:remove="all"> 

th:attr:设置标签属性。

<input th:attr="value=${user.name}"/> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wunianisme

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值