Thymeleaf学习记录(8)--表达式基本对象

基础对象

#ctx:上下文对象

 1 /*
 2  * ======================================================================
 3  * See javadoc API for class org.thymeleaf.context.IContext
 4  * ======================================================================
 5  */
 6 
 7 ${#ctx.locale}
 8 ${#ctx.variables}
 9 
10 /*
11  * ======================================================================
12  * See javadoc API for class org.thymeleaf.context.IWebContext
13  * ======================================================================
14  */
15 
16 ${#ctx.applicationAttributes}
17 ${#ctx.httpServletRequest}
18 ${#ctx.httpServletResponse}
19 ${#ctx.httpSession}
20 ${#ctx.requestAttributes}
21 ${#ctx.requestParameters}
22 ${#ctx.servletContext}
23 ${#ctx.sessionAttributes}

#locale:直接访问java.util.Locale与当前请求关联的

#varsorg.thymeleaf.context.VariablesMap上下文中所有变量的实例(通常包含在#ctx.variables加本地变量中的变量)。

 1 /*
 2  * ======================================================================
 3  * See javadoc API for class org.thymeleaf.context.VariablesMap
 4  * ======================================================================
 5  */
 6 
 7 ${#vars.get('foo')}
 8 ${#vars.containsKey('foo')}
 9 ${#vars.size()}
10 ...

请求/会话属性的Web上下文命名空间等。

  • param:用于检索请求参数。${param.foo}是一个String[]带有foo请求参数值的,因此${param.foo[0]}通常用于获取第一个值。
 1 •    /*
 2 •     * ============================================================================
 3 •     * See javadoc API for class org.thymeleaf.context.WebRequestParamsVariablesMap
 4 •     * ============================================================================
 5 •     */
 6  7 •    ${param.foo}              // Retrieves a String[] with the values of request parameter 'foo'
 8 •    ${param.size()}
 9 •    ${param.isEmpty()}
10 •    ${param.containsKey('foo')}
11 •    ...
  • session:用于检索会话属性。
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.context.WebSessionVariablesMap
 4 •     * ======================================================================
 5 •     */
 6  7 •    ${session.foo}                 // Retrieves the session atttribute 'foo'
 8 •    ${session.size()}
 9 •    ${session.isEmpty()}
10 •    ${session.containsKey('foo')}
11 •    ...
  • application:用于检索应用程序/ servlet上下文属性。
 1 •    /*
 2 •     * =============================================================================
 3 •     * See javadoc API for class org.thymeleaf.context.WebServletContextVariablesMap
 4 •     * =============================================================================
 5 •     */
 6  7 •    ${application.foo}              // Retrieves the ServletContext atttribute 'foo'
 8 •    ${application.size()}
 9 •    ${application.isEmpty()}
10 •    ${application.containsKey('foo')}
11 •    ...

Web上下文对象

#httpServletRequest:直接访问javax.servlet.http.HttpServletRequest与当前请求关联的对象

1 ${#httpServletRequest.getAttribute('foo')}
2 ${#httpServletRequest.getParameter('foo')}
3 ${#httpServletRequest.getContextPath()}
4 ${#httpServletRequest.getRequestName()}
5 ...
  • #httpSession:直接访问javax.servlet.http.HttpSession与当前请求关联的对象。
1 •    ${#httpSession.getAttribute('foo')}
2 •    ${#httpSession.id}
3 •    ${#httpSession.lastAccessedTime}
4 •    ...

Spring上下文对象

#themes:提供与Spring spring:themeJSP标记相同的功能

表达式实用程序对象

#datesjava.util.Date对象的实用方法

 1 /*
 2  * ======================================================================
 3  * See javadoc API for class org.thymeleaf.expression.Dates
 4  * ======================================================================
 5  */
 6 
 7 /*
 8  * Format date with the standard locale format
 9  * Also works with arrays, lists or sets
10  */
11 ${#dates.format(date)}
12 ${#dates.arrayFormat(datesArray)}
13 ${#dates.listFormat(datesList)}
14 ${#dates.setFormat(datesSet)}
15 
16 /*
17  * Format date with the ISO8601 format
18  * Also works with arrays, lists or sets
19  */
20 ${#dates.formatISO(date)}
21 ${#dates.arrayFormatISO(datesArray)}
22 ${#dates.listFormatISO(datesList)}
23 ${#dates.setFormatISO(datesSet)}
24 
25 /*
26  * Format date with the specified pattern
27  * Also works with arrays, lists or sets
28  */
29 ${#dates.format(date, 'dd/MMM/yyyy HH:mm')}
30 ${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')}
31 ${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')}
32 ${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')}
33 
34 /*
35  * Obtain date properties
36  * Also works with arrays, lists or sets
37  */
38 ${#dates.day(date)}                    // also arrayDay(...), listDay(...), etc.
39 ${#dates.month(date)}                  // also arrayMonth(...), listMonth(...), etc.
40 ${#dates.monthName(date)}              // also arrayMonthName(...), listMonthName(...), etc.
41 ${#dates.monthNameShort(date)}         // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
42 ${#dates.year(date)}                   // also arrayYear(...), listYear(...), etc.
43 ${#dates.dayOfWeek(date)}              // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
44 ${#dates.dayOfWeekName(date)}          // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
45 ${#dates.dayOfWeekNameShort(date)}     // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
46 ${#dates.hour(date)}                   // also arrayHour(...), listHour(...), etc.
47 ${#dates.minute(date)}                 // also arrayMinute(...), listMinute(...), etc.
48 ${#dates.second(date)}                 // also arraySecond(...), listSecond(...), etc.
49 ${#dates.millisecond(date)}            // also arrayMillisecond(...), listMillisecond(...), etc.
50 
51 /*
52  * Create date (java.util.Date) objects from its components
53  */
54 ${#dates.create(year,month,day)}
55 ${#dates.create(year,month,day,hour,minute)}
56 ${#dates.create(year,month,day,hour,minute,second)}
57 ${#dates.create(year,month,day,hour,minute,second,millisecond)}
58 
59 /*
60  * Create a date (java.util.Date) object for the current date and time
61  */
62 ${#dates.createNow()}
63 
64 ${#dates.createNowForTimeZone()}
65 
66 /*
67  * Create a date (java.util.Date) object for the current date (time set to 00:00)
68  */
69 ${#dates.createToday()}
70 
71 ${#dates.createTodayForTimeZone()}
View Code
  • #calendars:类似于#dates,但对于java.util.Calendar对象:
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Calendars
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Format calendar with the standard locale format
 9 •     * Also works with arrays, lists or sets
10 •     */
11 •    ${#calendars.format(cal)}
12 •    ${#calendars.arrayFormat(calArray)}
13 •    ${#calendars.listFormat(calList)}
14 •    ${#calendars.setFormat(calSet)}
15 16 •    /*
17 •     * Format calendar with the ISO8601 format
18 •     * Also works with arrays, lists or sets
19 •     */
20 •    ${#calendars.formatISO(cal)}
21 •    ${#calendars.arrayFormatISO(calArray)}
22 •    ${#calendars.listFormatISO(calList)}
23 •    ${#calendars.setFormatISO(calSet)}
24 25 •    /*
26 •     * Format calendar with the specified pattern
27 •     * Also works with arrays, lists or sets
28 •     */
29 •    ${#calendars.format(cal, 'dd/MMM/yyyy HH:mm')}
30 •    ${#calendars.arrayFormat(calArray, 'dd/MMM/yyyy HH:mm')}
31 •    ${#calendars.listFormat(calList, 'dd/MMM/yyyy HH:mm')}
32 •    ${#calendars.setFormat(calSet, 'dd/MMM/yyyy HH:mm')}
33 34 •    /*
35 •     * Obtain calendar properties
36 •     * Also works with arrays, lists or sets
37 •     */
38 •    ${#calendars.day(date)}                // also arrayDay(...), listDay(...), etc.
39 •    ${#calendars.month(date)}              // also arrayMonth(...), listMonth(...), etc.
40 •    ${#calendars.monthName(date)}          // also arrayMonthName(...), listMonthName(...), etc.
41 •    ${#calendars.monthNameShort(date)}     // also arrayMonthNameShort(...), listMonthNameShort(...), etc.
42 •    ${#calendars.year(date)}               // also arrayYear(...), listYear(...), etc.
43 •    ${#calendars.dayOfWeek(date)}          // also arrayDayOfWeek(...), listDayOfWeek(...), etc.
44 •    ${#calendars.dayOfWeekName(date)}      // also arrayDayOfWeekName(...), listDayOfWeekName(...), etc.
45 •    ${#calendars.dayOfWeekNameShort(date)} // also arrayDayOfWeekNameShort(...), listDayOfWeekNameShort(...), etc.
46 •    ${#calendars.hour(date)}               // also arrayHour(...), listHour(...), etc.
47 •    ${#calendars.minute(date)}             // also arrayMinute(...), listMinute(...), etc.
48 •    ${#calendars.second(date)}             // also arraySecond(...), listSecond(...), etc.
49 •    ${#calendars.millisecond(date)}        // also arrayMillisecond(...), listMillisecond(...), etc.
50 51 •    /*
52 •     * Create calendar (java.util.Calendar) objects from its components
53 •     */
54 •    ${#calendars.create(year,month,day)}
55 •    ${#calendars.create(year,month,day,hour,minute)}
56 •    ${#calendars.create(year,month,day,hour,minute,second)}
57 •    ${#calendars.create(year,month,day,hour,minute,second,millisecond)}
58 59 •    ${#calendars.createForTimeZone(year,month,day,timeZone)}
60 •    ${#calendars.createForTimeZone(year,month,day,hour,minute,timeZone)}
61 •    ${#calendars.createForTimeZone(year,month,day,hour,minute,second,timeZone)}
62 •    ${#calendars.createForTimeZone(year,month,day,hour,minute,second,millisecond,timeZone)}
63 64 •    /*
65 •     * Create a calendar (java.util.Calendar) object for the current date and time
66 •     */
67 •    ${#calendars.createNow()}
68 69 •    ${#calendars.createNowForTimeZone()}
70 71 •    /*
72 •     * Create a calendar (java.util.Calendar) object for the current date (time set to 00:00)
73 •     */
74 •    ${#calendars.createToday()}
75 76 •    ${#calendars.createTodayForTimeZone()}
View Code
  • #numbers:数字对象的实用方法:
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Numbers
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * ==========================
 9 •     * Formatting integer numbers
10 •     * ==========================
11 •     */
12 13 •    /* 
14 •     * Set minimum integer digits.
15 •     * Also works with arrays, lists or sets
16 •     */
17 •    ${#numbers.formatInteger(num,3)}
18 •    ${#numbers.arrayFormatInteger(numArray,3)}
19 •    ${#numbers.listFormatInteger(numList,3)}
20 •    ${#numbers.setFormatInteger(numSet,3)}
21 22 23 •    /* 
24 •     * Set minimum integer digits and thousands separator: 
25 •     * 'POINT', 'COMMA', 'WHITESPACE', 'NONE' or 'DEFAULT' (by locale).
26 •     * Also works with arrays, lists or sets
27 •     */
28 •    ${#numbers.formatInteger(num,3,'POINT')}
29 •    ${#numbers.arrayFormatInteger(numArray,3,'POINT')}
30 •    ${#numbers.listFormatInteger(numList,3,'POINT')}
31 •    ${#numbers.setFormatInteger(numSet,3,'POINT')}
32 33 34 •    /*
35 •     * ==========================
36 •     * Formatting decimal numbers
37 •     * ==========================
38 •     */
39 40 •    /*
41 •     * Set minimum integer digits and (exact) decimal digits.
42 •     * Also works with arrays, lists or sets
43 •     */
44 •    ${#numbers.formatDecimal(num,3,2)}
45 •    ${#numbers.arrayFormatDecimal(numArray,3,2)}
46 •    ${#numbers.listFormatDecimal(numList,3,2)}
47 •    ${#numbers.setFormatDecimal(numSet,3,2)}
48 49 •    /*
50 •     * Set minimum integer digits and (exact) decimal digits, and also decimal separator.
51 •     * Also works with arrays, lists or sets
52 •     */
53 •    ${#numbers.formatDecimal(num,3,2,'COMMA')}
54 •    ${#numbers.arrayFormatDecimal(numArray,3,2,'COMMA')}
55 •    ${#numbers.listFormatDecimal(numList,3,2,'COMMA')}
56 •    ${#numbers.setFormatDecimal(numSet,3,2,'COMMA')}
57 58 •    /*
59 •     * Set minimum integer digits and (exact) decimal digits, and also thousands and 
60 •     * decimal separator.
61 •     * Also works with arrays, lists or sets
62 •     */
63 •    ${#numbers.formatDecimal(num,3,'POINT',2,'COMMA')}
64 •    ${#numbers.arrayFormatDecimal(numArray,3,'POINT',2,'COMMA')}
65 •    ${#numbers.listFormatDecimal(numList,3,'POINT',2,'COMMA')}
66 •    ${#numbers.setFormatDecimal(numSet,3,'POINT',2,'COMMA')}
67 68 69 70 •    /*
71 •     * ==========================
72 •     * Utility methods
73 •     * ==========================
74 •     */
75 76 •    /*
77 •     * Create a sequence (array) of integer numbers going
78 •     * from x to y
79 •     */
80 •    ${#numbers.sequence(from,to)}
81 •    ${#numbers.sequence(from,to,step)}
View Code
  • #stringsString对象的实用方法
  1 /*
  2  * ======================================================================
  3  * See javadoc API for class org.thymeleaf.expression.Strings
  4  * ======================================================================
  5  */
  6 
  7 /*
  8  * Null-safe toString()
  9  */
 10 ${#strings.toString(obj)}                           // also array*, list* and set*
 11 
 12 /*
 13  * Check whether a String is empty (or null). Performs a trim() operation before check
 14  * Also works with arrays, lists or sets
 15  */
 16 ${#strings.isEmpty(name)}
 17 ${#strings.arrayIsEmpty(nameArr)}
 18 ${#strings.listIsEmpty(nameList)}
 19 ${#strings.setIsEmpty(nameSet)}
 20 
 21 /*
 22  * Perform an 'isEmpty()' check on a string and return it if false, defaulting to
 23  * another specified string if true.
 24  * Also works with arrays, lists or sets
 25  */
 26 ${#strings.defaultString(text,default)}
 27 ${#strings.arrayDefaultString(textArr,default)}
 28 ${#strings.listDefaultString(textList,default)}
 29 ${#strings.setDefaultString(textSet,default)}
 30 
 31 /*
 32  * Check whether a fragment is contained in a String
 33  * Also works with arrays, lists or sets
 34  */
 35 ${#strings.contains(name,'ez')}                     // also array*, list* and set*
 36 ${#strings.containsIgnoreCase(name,'ez')}           // also array*, list* and set*
 37 
 38 /*
 39  * Check whether a String starts or ends with a fragment
 40  * Also works with arrays, lists or sets
 41  */
 42 ${#strings.startsWith(name,'Don')}                  // also array*, list* and set*
 43 ${#strings.endsWith(name,endingFragment)}           // also array*, list* and set*
 44 
 45 /*
 46  * Substring-related operations
 47  * Also works with arrays, lists or sets
 48  */
 49 ${#strings.indexOf(name,frag)}                      // also array*, list* and set*
 50 ${#strings.substring(name,3,5)}                     // also array*, list* and set*
 51 ${#strings.substringAfter(name,prefix)}             // also array*, list* and set*
 52 ${#strings.substringBefore(name,suffix)}            // also array*, list* and set*
 53 ${#strings.replace(name,'las','ler')}               // also array*, list* and set*
 54 
 55 /*
 56  * Append and prepend
 57  * Also works with arrays, lists or sets
 58  */
 59 ${#strings.prepend(str,prefix)}                     // also array*, list* and set*
 60 ${#strings.append(str,suffix)}                      // also array*, list* and set*
 61 
 62 /*
 63  * Change case
 64  * Also works with arrays, lists or sets
 65  */
 66 ${#strings.toUpperCase(name)}                       // also array*, list* and set*
 67 ${#strings.toLowerCase(name)}                       // also array*, list* and set*
 68 
 69 /*
 70  * Split and join
 71  */
 72 ${#strings.arrayJoin(namesArray,',')}
 73 ${#strings.listJoin(namesList,',')}
 74 ${#strings.setJoin(namesSet,',')}
 75 ${#strings.arraySplit(namesStr,',')}                // returns String[]
 76 ${#strings.listSplit(namesStr,',')}                 // returns List<String>
 77 ${#strings.setSplit(namesStr,',')}                  // returns Set<String>
 78 
 79 /*
 80  * Trim
 81  * Also works with arrays, lists or sets
 82  */
 83 ${#strings.trim(str)}                               // also array*, list* and set*
 84 
 85 /*
 86  * Compute length
 87  * Also works with arrays, lists or sets
 88  */
 89 ${#strings.length(str)}                             // also array*, list* and set*
 90 
 91 /*
 92  * Abbreviate text making it have a maximum size of n. If text is bigger, it
 93  * will be clipped and finished in "..."
 94  * Also works with arrays, lists or sets
 95  */
 96 ${#strings.abbreviate(str,10)}                      // also array*, list* and set*
 97 
 98 /*
 99  * Convert the first character to upper-case (and vice-versa)
100  */
101 ${#strings.capitalize(str)}                         // also array*, list* and set*
102 ${#strings.unCapitalize(str)}                       // also array*, list* and set*
103 
104 /*
105  * Convert the first character of every word to upper-case
106  */
107 ${#strings.capitalizeWords(str)}                    // also array*, list* and set*
108 ${#strings.capitalizeWords(str,delimiters)}         // also array*, list* and set*
109 
110 /*
111  * Escape the string
112  */
113 ${#strings.escapeXml(str)}                          // also array*, list* and set*
114 ${#strings.escapeJava(str)}                         // also array*, list* and set*
115 ${#strings.escapeJavaScript(str)}                   // also array*, list* and set*
116 ${#strings.unescapeJava(str)}                       // also array*, list* and set*
117 ${#strings.unescapeJavaScript(str)}                 // also array*, list* and set*
118 
119 /*
120  * Null-safe comparison and concatenation
121  */
122 ${#strings.equals(first, second)}
123 ${#strings.equalsIgnoreCase(first, second)}
124 ${#strings.concat(values...)}
125 ${#strings.concatReplaceNulls(nullValue, values...)}
126 
127 /*
128  * Random
129  */
130 ${#strings.randomAlphanumeric(count)}
View Code
  • #objects:一般对象的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Objects
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Return obj if it is not null, and default otherwise
 9 •     * Also works with arrays, lists or sets
10 •     */
11 •    ${#objects.nullSafe(obj,default)}
12 •    ${#objects.arrayNullSafe(objArray,default)}
13 •    ${#objects.listNullSafe(objList,default)}
14 •    ${#objects.setNullSafe(objSet,default)}
View Code
  • #bools:布尔评估的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Bools
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Evaluate a condition in the same way that it would be evaluated in a th:if tag
 9 •     * (see conditional evaluation chapter afterwards).
10 •     * Also works with arrays, lists or sets
11 •     */
12 •    ${#bools.isTrue(obj)}
13 •    ${#bools.arrayIsTrue(objArray)}
14 •    ${#bools.listIsTrue(objList)}
15 •    ${#bools.setIsTrue(objSet)}
16 17 •    /*
18 •     * Evaluate with negation
19 •     * Also works with arrays, lists or sets
20 •     */
21 •    ${#bools.isFalse(cond)}
22 •    ${#bools.arrayIsFalse(condArray)}
23 •    ${#bools.listIsFalse(condList)}
24 •    ${#bools.setIsFalse(condSet)}
25 26 •    /*
27 •     * Evaluate and apply AND operator
28 •     * Receive an array, a list or a set as parameter
29 •     */
30 •    ${#bools.arrayAnd(condArray)}
31 •    ${#bools.listAnd(condList)}
32 •    ${#bools.setAnd(condSet)}
33 34 •    /*
35 •     * Evaluate and apply OR operator
36 •     * Receive an array, a list or a set as parameter
37 •     */
38 •    ${#bools.arrayOr(condArray)}
39 •    ${#bools.listOr(condList)}
40 •    ${#bools.setOr(condSet)}
View Code
  • #arrays:数组的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Arrays
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Converts to array, trying to infer array component class.
 9 •     * Note that if resulting array is empty, or if the elements
10 •     * of the target object are not all of the same class,
11 •     * this method will return Object[].
12 •     */
13 •    ${#arrays.toArray(object)}
14 15 •    /*
16 •     * Convert to arrays of the specified component class.
17 •     */
18 •    ${#arrays.toStringArray(object)}
19 •    ${#arrays.toIntegerArray(object)}
20 •    ${#arrays.toLongArray(object)}
21 •    ${#arrays.toDoubleArray(object)}
22 •    ${#arrays.toFloatArray(object)}
23 •    ${#arrays.toBooleanArray(object)}
24 25 •    /*
26 •     * Compute length
27 •     */
28 •    ${#arrays.length(array)}
29 30 •    /*
31 •     * Check whether array is empty
32 •     */
33 •    ${#arrays.isEmpty(array)}
34 35 •    /*
36 •     * Check if element or elements are contained in array
37 •     */
38 •    ${#arrays.contains(array, element)}
39 •    ${#arrays.containsAll(array, elements)}
View Code
  • #lists:列表的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Lists
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Converts to list
 9 •     */
10 •    ${#lists.toList(object)}
11 12 •    /*
13 •     * Compute size
14 •     */
15 •    ${#lists.size(list)}
16 17 •    /*
18 •     * Check whether list is empty
19 •     */
20 •    ${#lists.isEmpty(list)}
21 22 •    /*
23 •     * Check if element or elements are contained in list
24 •     */
25 •    ${#lists.contains(list, element)}
26 •    ${#lists.containsAll(list, elements)}
27 28 •    /*
29 •     * Sort a copy of the given list. The members of the list must implement
30 •     * comparable or you must define a comparator.
31 •     */
32 •    ${#lists.sort(list)}
33 •    ${#lists.sort(list, comparator)
View Code
  • #sets:集合的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Sets
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Converts to set
 9 •     */
10 •    ${#sets.toSet(object)}
11 12 •    /*
13 •     * Compute size
14 •     */
15 •    ${#sets.size(set)}
16 17 •    /*
18 •     * Check whether set is empty
19 •     */
20 •    ${#sets.isEmpty(set)}
21 22 •    /*
23 •     * Check if element or elements are contained in set
24 •     */
25 •    ${#sets.contains(set, element)}
26 •    ${#sets.containsAll(set, elements)}
View Code
  • #maps:地图的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Maps
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Compute size
 9 •     */
10 •    ${#maps.size(map)}
11 12 •    /*
13 •     * Check whether map is empty
14 •     */
15 •    ${#maps.isEmpty(map)}
16 17 •    /*
18 •     * Check if key/s or value/s are contained in maps
19 •     */
20 •    ${#maps.containsKey(map, key)}
21 •    ${#maps.containsAllKeys(map, keys)}
22 •    ${#maps.containsValue(map, value)}
23 •    ${#maps.containsAllValues(map, value)}
View Code
  • #aggregates:用于在数组或集合上创建聚合的实用程序方法
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Aggregates
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Compute sum. Returns null if array or collection is empty
 9 •     */
10 •    ${#aggregates.sum(array)}
11 •    ${#aggregates.sum(collection)}
12 13 •    /*
14 •     * Compute average. Returns null if array or collection is empty
15 •     */
16 •    ${#aggregates.avg(array)}
17 •    ${#aggregates.avg(collection)}
View Code
  • #messages:用于在变量表达式中获取外部化消息的实用程序方法,与使用#{...}语法获取它们的方式相同。
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Messages
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Obtain externalized messages. Can receive a single key, a key plus arguments,
 9 •     * or an array/list/set of keys (in which case it will return an array/list/set of 
10 •     * externalized messages).
11 •     * If a message is not found, a default message (like '??msgKey??') is returned.
12 •     */
13 •    ${#messages.msg('msgKey')}
14 •    ${#messages.msg('msgKey', param1)}
15 •    ${#messages.msg('msgKey', param1, param2)}
16 •    ${#messages.msg('msgKey', param1, param2, param3)}
17 •    ${#messages.msgWithParams('msgKey', new Object[] {param1, param2, param3, param4})}
18 •    ${#messages.arrayMsg(messageKeyArray)}
19 •    ${#messages.listMsg(messageKeyList)}
20 •    ${#messages.setMsg(messageKeySet)}
21 22 •    /*
23 •     * Obtain externalized messages or null. Null is returned instead of a default
24 •     * message if a message for the specified key is not found.
25 •     */
26 •    ${#messages.msgOrNull('msgKey')}
27 •    ${#messages.msgOrNull('msgKey', param1)}
28 •    ${#messages.msgOrNull('msgKey', param1, param2)}
29 •    ${#messages.msgOrNull('msgKey', param1, param2, param3)}
30 •    ${#messages.msgOrNullWithParams('msgKey', new Object[] {param1, param2, param3, param4})}
31 •    ${#messages.arrayMsgOrNull(messageKeyArray)}
32 •    ${#messages.listMsgOrNull(messageKeyList)}
33 •    ${#messages.setMsgOrNull(messageKeySet)}
View Code
  • #ids:用于处理id可能重复的属性的实用程序方法(例如,作为迭代的结果)。
 1 •    /*
 2 •     * ======================================================================
 3 •     * See javadoc API for class org.thymeleaf.expression.Ids
 4 •     * ======================================================================
 5 •     */
 6  7 •    /*
 8 •     * Normally used in th:id attributes, for appending a counter to the id attribute value
 9 •     * so that it remains unique even when involved in an iteration process.
10 •     */
11 •    ${#ids.seq('someId')}
12 13 •    /*
14 •     * Normally used in th:for attributes in <label> tags, so that these labels can refer to Ids
15 •     * generated by means if the #ids.seq(...) function.
16 •     *
17 •     * Depending on whether the <label> goes before or after the element with the #ids.seq(...)
18 •     * function, the "next" (label goes before "seq") or the "prev" function (label goes after 
19 •     * "seq") function should be called.
20 •     */
21 •    ${#ids.next('someId')}
22 •    ${#ids.prev('someId')}
View Code

使用示例:

原文地址:https://www.cnblogs.com/feichangnice/p/10168987.html