-
表达式语法
-
Simple expressions:
-
Variable Expressions: ${...}
-
Selection Variable Expressions: *{...}
-
Message Expressions: #{...}
-
Link URL Expressions: @{...}
-
th:src="@{/js/test.js}"
-
定义 url 链接
-
Fragment Expressions: ~{...}
-
Literals(字面量)
-
Text literals: 'one text' , 'Another one!' ,…
-
Number literals: 0 , 34 , 3.0 , 12.3 ,…
-
Boolean literals: true , false
-
Null literal: null
-
Literal tokens: one , sometext , main ,…
-
Text operations:(文本操作)
-
Arithmetic operations:(数学运算)
-
Binary operators: + , - , * , / , %
-
Minus sign (unary operator): -
-
Boolean operations:(布尔运算)
-
Binary operators: and , or
-
Boolean negation (unary operator): ! , not
-
Comparisons and equality:(比较运算)
-
Comparators: > , < , >= , <= ( gt , lt , ge , le )
-
Equality operators: == , != ( eq , ne )
-
Conditional operators:(条件运算)
-
Special tokens:(特殊操作)
-
Page 17 of 106
-
No-Operation: _
<!DOCTYPE HTML>
<!-- 导入thymeleaf -->
<html lang="en" xmlns:th="https://www.thymeleaf.org">
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!-- th:href = '@{/css/success.css}' 中的css前面的 / 不能省略,会报错 -->
<link type='text/css' rel='styleSheet' th:href='@{/css/success.css}'/>
<script th:src="@{/js/test.js}"></script>
</head>
<body>
<!-- 使用th: 任意html标签, ${name}取索引为'name'的元素的值,如后端传入name -->
<div th:id="${name}"></div>
<!-- 注意,使用了th:xxx = "" 之后,外面的双引号是th的,所以字符串还得自己再加引号,不然会出错 -->
<span>账号:</span><input type="text" th:placeholder=" 'QQ号码/手机/邮箱' ">
<!-- 如果不用th: ,则原来只要有一对引号就可以了 -->
<span>密码:</span><input type="password" placeholder="密码">
<hr>
<!-- 使用th:each 遍历链表,user依次取自users中的元素 -->
<tr th:each="user : ${users}">
<!-- 会自动生成多个<td> -->
<td th:text="${user}"></td>
</tr>
<hr>
<!-- if(name == 'XiaoMing') .... -->
<h4 th:if="${name} == 'XiaoMing' " th:text="'This true!'" ></h4>
<hr>
<!-- 打印四个<h4> -->
<h4 th:text="${user}" th:each="user : ${users}"></h4>
<hr>
<!-- 一个<h4>中打印四个<span> -->
<h4>
<span th:text="${user} + ' ' " th:each="user : ${users}"></span>
</h4>
</body>
</html>