thymeleaf 字面量
********************
字面量
字面量分类:text、number、boolean、null
字面量构成:letters(a-z、A-Z)、numbers(0-9)、中括号([、])、dots(.)、破折号(-)、下划线(_)
说明:如果text中包含空格、逗号,需要使用单引号
运算符( ?:) 使用
param?value:value2 ==> param为true返回value,为false返回value2
param?value ==> param 为true返回value,为false返回null
param?:default_value ==> param为null返回default_value,不为null时返回原值
说明:param为null时,thymeleaf判定为false
********************
示例
test.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div th:align="center" style="color: coral">
<strong>
<span style="color: purple">text literals:</span><br>
<span th:text="百度-[www.baidu.com]_taobao-[www.taobao.com]"></span><br>
<span th:text="'hello world'"></span><br>
<span th:text="'hello '+ ' 瓜田李下'"></span><br>
<span th:text="|hello 瓜田李下|"></span><br>
<span th:text="'hello '+| 瓜田李下, 欢迎欢迎 |"></span>
</strong>
</div><br>
<div th:align="center" style="color: coral">
<strong>
<span style="color: purple">number literals</span><br>
1 ==> <span th:text="1"></span><br>
2+2 ==> <span th:text="2+2"></span><br>
3%5 ==> <span th:text="3%5"></span><br>
13/5 ==> <span th:text="13/5"></span><br>
2*8 ==> <span th:text="2*8"></span><br>
3-9 ==> <span th:text="3-9"></span><br>
</strong>
</div><br>
<div th:align="center" style="color: coral">
<strong>
<span style="color: purple">boolean literals</span><br>
1>2 ==> <span th:text="1>2"></span><br>
1>2 ==> <span th:text="1>2?true:false"></span><br>
1>2 ==> <span th:text="1>2?:false"></span><br>
2>1 ==> <span th:text="2>1?true"></span>
</strong>
</div><br>
<div th:align="center" style="color: coral">
<strong>
<span style="color: purple">null literals</span><br>
null ==> <span th:text="null">th:text="null"</span><br>
null?:'值为null' ==> <span th:text="null?:'值为null'"></span><br>
false?:'值为false' ==> <span th:text="false?:'值为false'"></span>
</strong>
</div><br>
<div th:align="center" style="color: coral">
<strong>
<span style="color: purple">不执行任何操作</span><br>
_ ==> <span th:text="_">不执行任何操作</span><br>
_ ==> <span th:text="'_'">不执行任何操作</span>
</strong>
</div>
</body>
</html>