当前位置:网站首页>Thymeleaf 常用函數
Thymeleaf 常用函數
2022-07-05 14:17:00 【fengyehongWorld】
目錄
- 一. #dates
- 二. #numbers
- 三. #strings
- `#strings.toString`
- `#strings.isEmpty`
- `#strings.defaultString`
- `#strings.contains`
- `#strings.containsIgnoreCase`
- `#strings.startsWith`
- `#strings.endsWith`
- `#strings.indexOf`
- `#strings.substring`
- `#strings.replace`
- `#strings.prepend`
- `#strings.append`
- `#strings.toUpperCase`
- `#strings.length`
- `#strings.trim`
- `#strings.abbreviate`
- 四. #objects
- 五. #bools
一. #dates
處理日期數據.生成,轉換,獲取日期的具體天數和年數。
#dates.createNow
生成當前的日期(相當於Java的new Date())
<span th:text="${#dates.createNow()}"></span>
<!--結果頁面-->
<span>Sun May 16 09:38:33 CST 2021</span>
#dates.create
- 構造一個日期
<span th:text="${#dates.create('2019','05','31','10','18')}"></span>
<!--結果頁面-->
<span>Fri May 31 10:18:00 CST 2019</span>
#dates.format
- 對日期進行格式化
- 對日期進行格式化的時候,日期一定要是
new Date()類型,不能是字符串日期類型,否則會報錯.
<span th:text="*{#dates.format(#dates.createNow())}"></span>
<!--結果頁面-->
<span>2021年5月16日 上午09時40分46秒</span>
- 按照指定格式對日期進行格式化
<span th:text="*{#dates.format(#dates.createNow(), 'yyyy/MM/dd HH:mm')}"></span>
<!--結果頁面-->
<span>2021/05/16 09:43</span>
<span th:text="*{#dates.format(#dates.createNow(), 'yyyy年MM月dd日 HH:mm')}"></span>
<!--結果頁面-->
<span>2021年05月16日 09:43</span>
#dates.year
- 獲取年
<span th:text="*{#dates.year(#dates.createNow())}"></span>
<!--結果頁面-->
<span>2021</span>
#dates.month
- 獲取月份(使用內聯的方式)
<span>[[*{#dates.month(#dates.createNow())}]]</span>
<!--結果頁面-->
<span>5</span>
#dates.monthName
<span th:text="*{#dates.monthName(#dates.createNow())}"></span>
<!--結果頁面-->
<span>五月</span>
#dates.monthNameShort
<span th:text="*{#dates.monthNameShort(#dates.createNow())}"></span>
<!--結果頁面-->
<span>五月</span>
#dates.day
- 獲取日期
<span th:text="*{#dates.day(#dates.createNow())}"></span>
<!--結果頁面-->
<span>30</span>
#dates.dayOfWeek
獲取本周的第幾天(外國的情况,周日是本周的第一天)
<span th:text="*{#dates.dayOfWeek(#dates.createNow())}"></span>
<!--結果頁面-->
<span>1</span>
#dates.dayOfWeekName
<span th:text="*{#dates.dayOfWeekName(#dates.createNow())}"></span>
<!--結果頁面-->
<span>星期日</span>
#dates.dayOfWeekNameShort
<span th:text="*{#dates.dayOfWeekNameShort(#dates.createNow())}"></span>
<!--結果頁面-->
<span>星期日</span>
#dates.hour
- 獲取當前的小時
<span th:text="*{#dates.hour(#dates.createNow())}"></span>
<!--結果頁面-->
<span>10</span>
#dates.minute
- 獲取當前的分鐘
<span th:text="*{#dates.minute(#dates.createNow())}"></span>
<!--結果頁面-->
<span>6</span>
#dates.second
- 獲取當前的秒
<span th:text="*{#dates.second(#dates.createNow())}"></span>
<!--結果頁面-->
<span>12</span>
#dates.millisecond
- 獲取當前的毫秒數
<span th:text="*{#dates.millisecond(#dates.createNow())}"></span>
<!--結果頁面-->
<span>221</span>
二. #numbers
處理數字數據的轉換
- 對不够比特數的數字進行補0(formatInteger)
- 設置千比特分隔符(formatInteger)
- 精確小數點(formatDecimal)
- 設置百分號(formatPercent)
- 生成數組(sequence)
#numbers.formatInteger
- 對不够比特數的數字進行補0
<p th:text="${#numbers.formatInteger('123',4)}"></p> // 0123
<p th:text="${#numbers.formatInteger('123',2)}"></p> // 123
- 設置千比特分隔符
.
<p th:text="${#numbers.formatInteger('1000',2,'POINT')}"></p> // 1.000
<p th:text="${#numbers.formatInteger('1000',6,'POINT')}"></p> // 001.000
<p th:text="${#numbers.formatInteger('1000',7,'POINT')}"></p> // 0.001.000
設置千比特分隔符,
<p th:text="${#numbers.formatInteger('1000', 2, 'COMMA')}"></p> // 1,000
<div th:text="*{#numbers.formatInteger('1000', 0, 'COMMA')}"></div> // 1,000
設置千比特分隔符為空白
<p th:text="${#numbers.formatInteger('1000', 2, 'WHITESPACE')}"></p> // 1 000
#numbers.formatDecimal
精確小數點
<p th:text="${#numbers.formatDecimal('10.123', 3, 2)}"></p> // 010.12
#numbers.formatCurrency
錢顯示符號
<p th:text="${#numbers.formatCurrency('1000')}"></p> // ¥1,000.00
#numbers.formatPercent
百分比操作
<p th:text="${#numbers.formatPercent('0.2',2, 4)}"></p> // 20.0000%
<p th:text="${#numbers.formatPercent('0.2',3, 2)}"></p> // 020.00%
三. #strings
- 字符串轉換(toString)
- 檢查字符串是否為空(isEmpty)
- 字符串是為空替換操作(defaultString)
- 檢查字符串中是否包含某個字符串(contains containsIgnoreCase)
- 檢查字符串是以片段開頭還是結尾(startsWith endsWith)
- 截取(substring substringAfter)
- 替換(replace)
- 追加(prepend append)
- 變更大小寫(toUpperCase toLowerCase)
- 拆分和組合字符串(arrayJoin arraySplit)
- 去空格(trim)
- 縮寫文本(abbreviate)
- 字符串連接(concat)
#strings.toString
// java代碼
Object object = "123";
<p th:text="${#strings.toString(object)}"></p>
<p>123</p>
#strings.isEmpty
String name = null;
<p th:text="${#strings.isEmpty(name)}"></p>
<p>true</p>
#strings.defaultString
String text = null;
String text1 = "123";
<p th:text="${#strings.defaultString(text,'該值為null')}"></p>
<p>該值為null</p>
<p th:text="${#strings.defaultString(text1,'該值為null')}"></p>
<p>123</p>
#strings.contains
<p th:text="${#strings.contains('abcez','ez')}"></p>
<p>true</p>
#strings.containsIgnoreCase
<p th:text="${#strings.containsIgnoreCase('abcEZ','ez')}"></p>
<p>true</p>
#strings.startsWith
<p th:text="${#strings.startsWith('Donabcez','Don')}"></p>
<p>true</p>
#strings.endsWith
<p th:text="${#strings.endsWith('Donabcezn','n')}"></p>
<p>true</p>
#strings.indexOf
<p th:text="${#strings.indexOf('abcefg','e')}"></p>
<p>3</p>
#strings.substring
<p th:text="${#strings.substring('abcefg',3,5)}"></p>
<p>ef</p>
#strings.replace
<p th:text="${#strings.replace('lasabce','las','ler')}"></p>
<p>lerabce</p>
#strings.prepend
<p th:text="${#strings.prepend('abc','012')}"></p>
<p>012abc</p>
#strings.append
<p th:text="${#strings.append('abc','456')}"></p>
<p>abc456</p>
#strings.toUpperCase
<p th:text="${#strings.toLowerCase('ABC')}"></p>
<p>abc</p>
#strings.length
<p th:text="${#strings.length('abc')}"></p>
<p>3</p>
#strings.trim
<p th:text="${#strings.trim(' abc ')}"></p>
<p>abc</p>
#strings.abbreviate
<p th:text="${#strings.abbreviate('12345678910',10)}"></p>
<p>1234567...</p>
四. #objects
#objects.nullSafe
<p th:text="${#objects.nullSafe(null,'該對象為null')}"></p>
<p>該對象為null</p>
五. #bools
#bools.isTrue
<p th:text="${#bools.isTrue(true)} "></p>
<p>true</p>
<p th:text="${#bools.isTrue(false)} "></p>
<p>false</p>
<p th:text="${#bools.isTrue('on')} "></p>
<p>true</p>
<p th:text="${#bools.isTrue('off')} "></p>
<p>false</p>
<p th:text="${#bools.isTrue('true')} "></p>
<p>true</p>
<p th:text="${#bools.isTrue('false')} "></p>
<p>false</p>
<p th:text="${#bools.isTrue(1)} "></p>
<p>true</p>
<p th:text="${#bools.isTrue(0)} "></p>
<p>false</p>
边栏推荐
- 魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
- 金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
- Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
- 根据CronSequenceGenerator计算cron表达式的时间
- OSI and tcp/ip protocol cluster
- C - Divisors of the Divisors of An Integer Gym - 102040C
- Some ideas about Apache mesos
- Show strength. In this way, the mobile phone will not be difficult to move forward
- Scenario based technology architecture process based on tidb - Theory
- 做自媒体视频二次剪辑,怎样剪辑不算侵权
猜你喜欢

Simple process of penetration test

分享 12 个最常用的正则表达式,能解决你大部分问题

软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】

Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue

网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理

TDengine 社区问题双周精选 | 第三期

Postman简介、安装、入门使用方法详细攻略!

Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
![Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]](/img/c2/a5f5fe17a6bd1f6f9df828ddd224d6.png)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]

魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
随机推荐
The forked VM terminated without saying properly goodbye
Hongmeng fourth training
Introduction, installation, introduction and detailed introduction to postman!
Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
C - Divisors of the Divisors of An Integer Gym - 102040C
SSH免密码登录详解
Lepton 无损压缩原理及性能分析
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
3W principle [easy to understand]
04_ Use of solrj7.3 of solr7.3
世界环境日 | 周大福用心服务推动减碳环保
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
VC开发非MFC程序内存泄漏跟踪代码
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to each vari
TDengine 社区问题双周精选 | 第三期
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
LeetCode_ 69 (square root of x)