thymeleaf 字面量


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>

 

 

                           

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值