当前位置:网站首页>Thymeleaf common functions

Thymeleaf common functions

2022-07-05 14:17:00 fengyehongWorld

One . #dates

Processing date data . Generate , transformation , Get the specific number of days and years of the date .

#dates.createNow

Generate current date ( amount to Java Of new Date())

<span th:text="${#dates.createNow()}"></span>

<!-- Results page -->
<span>Sun May 16 09:38:33 CST 2021</span>

#dates.create

  • Construct a date
<span th:text="${#dates.create('2019','05','31','10','18')}"></span>

<!-- Results page -->
<span>Fri May 31 10:18:00 CST 2019</span>

#dates.format

  • Format the date
  • When formatting the date , The date must be new Date() type , Cannot be string date type , Otherwise, an error will be reported .
<span th:text="*{#dates.format(#dates.createNow())}"></span>

<!-- Results page -->
<span>2021 year 5 month 16 Japan   In the morning 09 when 40 branch 46 second </span>
  • Format the date in the specified format
 <span th:text="*{#dates.format(#dates.createNow(), 'yyyy/MM/dd HH:mm')}"></span>
<!-- Results page -->
<span>2021/05/16 09:43</span>

<span th:text="*{#dates.format(#dates.createNow(), 'yyyy year MM month dd Japan  HH:mm')}"></span>
<!-- Results page -->
<span>2021 year 05 month 16 Japan  09:43</span>

#dates.year

  • Year of acquisition
<span th:text="*{#dates.year(#dates.createNow())}"></span>

<!-- Results page -->
<span>2021</span>

#dates.month

  • Get month ( Use inline )
<span>[[*{#dates.month(#dates.createNow())}]]</span>

<!-- Results page -->
<span>5</span>

#dates.monthName

<span th:text="*{#dates.monthName(#dates.createNow())}"></span>

<!-- Results page -->
<span> May </span>

#dates.monthNameShort

<span th:text="*{#dates.monthNameShort(#dates.createNow())}"></span>

<!-- Results page -->
<span> May </span>

#dates.day

  • Get date
<span th:text="*{#dates.day(#dates.createNow())}"></span>

<!-- Results page -->
<span>30</span>

#dates.dayOfWeek

Get the day of the week ( The situation in foreign countries , Sunday is the first day of the week )

<span th:text="*{#dates.dayOfWeek(#dates.createNow())}"></span>

<!-- Results page -->
<span>1</span>

#dates.dayOfWeekName

<span th:text="*{#dates.dayOfWeekName(#dates.createNow())}"></span>

<!-- Results page -->
<span> Sunday </span>

#dates.dayOfWeekNameShort

<span th:text="*{#dates.dayOfWeekNameShort(#dates.createNow())}"></span>

<!-- Results page -->
<span> Sunday </span>

#dates.hour

  • Get the current hour
<span th:text="*{#dates.hour(#dates.createNow())}"></span>

<!-- Results page -->
<span>10</span>

#dates.minute

  • Get the current minute
<span th:text="*{#dates.minute(#dates.createNow())}"></span>

<!-- Results page -->
<span>6</span>

#dates.second

  • Get the current second
<span th:text="*{#dates.second(#dates.createNow())}"></span>

<!-- Results page -->
<span>12</span>

#dates.millisecond

  • Gets the current number of milliseconds
<span th:text="*{#dates.millisecond(#dates.createNow())}"></span>

<!-- Results page -->
<span>221</span>

Two . #numbers

Handle the conversion of digital data

  • Make up for numbers that are not enough 0(formatInteger)
  • Set thousands separator (formatInteger)
  • Exact decimal point (formatDecimal)
  • Set the percent sign (formatPercent)
  • Generating arrays (sequence)

#numbers.formatInteger

  • Make up for numbers that are not enough 0
<p th:text="${#numbers.formatInteger('123',4)}"></p>  // 0123
<p th:text="${#numbers.formatInteger('123',2)}"></p>  // 123
  • Set thousands separator .
<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

Set thousands separator ,

<p th:text="${#numbers.formatInteger('1000', 2, 'COMMA')}"></p>  // 1,000
<div th:text="*{#numbers.formatInteger('1000', 0, 'COMMA')}"></div>  // 1,000

Set the thousand separator to blank

<p th:text="${#numbers.formatInteger('1000', 2, 'WHITESPACE')}"></p>  // 1 000

#numbers.formatDecimal

Exact decimal point

<p th:text="${#numbers.formatDecimal('10.123', 3, 2)}"></p>  // 010.12

#numbers.formatCurrency

Money display symbol

<p th:text="${#numbers.formatCurrency('1000')}"></p>  // ¥1,000.00

#numbers.formatPercent

Percentage operation

<p th:text="${#numbers.formatPercent('0.2',2, 4)}"></p>  // 20.0000%
<p th:text="${#numbers.formatPercent('0.2',3, 2)}"></p>  // 020.00%

3、 ... and . #strings

  • String conversion (toString)
  • Check if the string is empty (isEmpty)
  • String is an empty replace operation (defaultString)
  • Check if the string contains a string (contains containsIgnoreCase)
  • Check whether the string starts or ends with a fragment (startsWith endsWith)
  • Intercept (substring substringAfter)
  • Replace (replace)
  • Additional (prepend append)
  • Change case (toUpperCase toLowerCase)
  • Split and combine strings (arrayJoin arraySplit)
  • Go to space (trim)
  • Abbreviated text (abbreviate)
  • String connection (concat)

#strings.toString

// java Code 
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,' The value is null')}"></p>
<p> The value is null</p>

<p th:text="${#strings.defaultString(text1,' The value is 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>

Four . #objects

#objects.nullSafe

<p th:text="${#objects.nullSafe(null,' The object of null')}"></p>
<p> The object of null</p>

5、 ... and . #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>
原网站

版权声明
本文为[fengyehongWorld]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051410196379.html

随机推荐