第十节:Thymeleaf内嵌变量Utilities详细

一:#dates

/*

* =================================================================

* See javadoc API for class org.thymeleaf.expression.Dates

* =================================================================

*/

/*

* Format date with the standard locale format

* Also works with arrays, lists or sets

*/

${#dates.format(date)}

${#dates.arrayFormat(datesArray)}

${#dates.listFormat(datesList)}

${#dates.setFormat(datesSet)}

/*

* Format date with the ISO8601 format

* Also works with arrays, lists or sets

*/

${#dates.formatISO(date)}

${#dates.arrayFormatISO(datesArray)}

${#dates.listFormatISO(datesList)}

${#dates.setFormatISO(datesSet)}

/*

* Format date with the specified pattern

* Also works with arrays, lists or sets

*/

${#dates.format(date, 'dd/MMM/yyyy HH:mm')}

${#dates.arrayFormat(datesArray, 'dd/MMM/yyyy HH:mm')}

${#dates.listFormat(datesList, 'dd/MMM/yyyy HH:mm')}

${#dates.setFormat(datesSet, 'dd/MMM/yyyy HH:mm')}

/*

* Obtain date properties

* Also works with arrays, lists or sets

*/

${#dates.day(date)} // also arrayDay(...), listDay(...), etc.

${#dates.month(date)} // also arrayMonth(...), listMonth(...), etc.

${#dates.monthName(date)} // also arrayMonthName(...), listMonthName(...), etc.

${#dates.monthNameShort(date)} // also arrayMonthNameShort(...),listMonthNameShort(...), etc.

${#dates.year(date)} // also arrayYear(...), listYear(...), etc.

${#dates.dayOfWeek(date)} // also arrayDayOfWeek(...), listDayOfWeek(...), etc.

${#dates.dayOfWeekName(date)} // also arrayDayOfWeekName(...),listDayOfWeekName(...), etc.

${#dates.dayOfWeekNameShort(date)} // also arrayDayOfWeekNameShort(...),listDayOfWeekNameShort(...), etc.

${#dates.hour(date)} // also arrayHour(...), listHour(...), etc.

${#dates.minute(date)} // also arrayMinute(...), listMinute(...), etc.

${#dates.second(date)} // also arraySecond(...), listSecond(...), etc.

${#dates.millisecond(date)} // also arrayMillisecond(...),listMillisecond(...), etc.

/*

* Create date (java.util.Date) objects from its components

*/

${#dates.create(year,month,day)}

${#dates.create(year,month,day,hour,minute)}

${#dates.create(year,month,day,hour,minute,second)}

${#dates.create(year,month,day,hour,minute,second)}

${#dates.create(year,month,day,hour,minute,second,millisecond)}

/*

* Create a date (java.util.Date) object for the current date and time

*/

${#dates.createNow()}

/*

* Create a date (java.util.Date) object for the current date (time set to00:00)

*/

${#dates.createToday()}

二:#Calendars:

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Calendars

* ====================================================================

*/

/*

* Format calendar with the standard locale format

* Also works with arrays, lists or sets

*/

${#calendars.format(cal)}

${#calendars.arrayFormat(calArray)}

${#calendars.listFormat(calList)}

${#calendars.setFormat(calSet)}

/*

* Format calendar with the ISO8601 format

* Also works with arrays, lists or sets

*/

${#calendars.formatISO(cal)}

${#calendars.arrayFormatISO(calArray)}

${#calendars.listFormatISO(calList)}

${#calendars.setFormatISO(calSet)}

/*

* Format calendar with the specified pattern

* Also works with arrays, lists or sets

*/

${#calendars.format(cal, 'dd/MMM/yyyy HH:mm')}

${#calendars.arrayFormat(calArray, 'dd/MMM/yyyy HH:mm')}

${#calendars.listFormat(calList, 'dd/MMM/yyyy HH:mm')}

${#calendars.setFormat(calSet, 'dd/MMM/yyyy HH:mm')}

/*

* Obtain calendar properties

* Also works with arrays, lists or sets

*/

${#calendars.day(date)} // also arrayDay(...), listDay(...), etc.

${#calendars.month(date)} // also arrayMonth(...), listMonth(...), etc.

${#calendars.monthName(date)} // also arrayMonthName(...), listMonthName(...),etc.

${#calendars.monthNameShort(date)} // also arrayMonthNameShort(...),listMonthNameShort(...), etc.

${#calendars.year(date)} // also arrayYear(...), listYear(...), etc.

${#calendars.dayOfWeek(date)} // also arrayDayOfWeek(...), listDayOfWeek(...),etc.

${#calendars.dayOfWeekName(date)} // also arrayDayOfWeekName(...),listDayOfWeekName(...), etc.

${#calendars.dayOfWeekNameShort(date)} // also arrayDayOfWeekNameShort(...),listDayOfWeekNameShort(...), etc.

${#calendars.hour(date)} // also arrayHour(...), listHour(...), etc.

${#calendars.hour(date)} // also arrayHour(...), listHour(...), etc.

${#calendars.minute(date)} // also arrayMinute(...), listMinute(...), etc.

${#calendars.second(date)} // also arraySecond(...), listSecond(...), etc.

${#calendars.millisecond(date)} // also arrayMillisecond(...),listMillisecond(...), etc.

/*

* Create calendar (java.util.Calendar) objects from its components

*/

${#calendars.create(year,month,day)}

${#calendars.create(year,month,day,hour,minute)}

${#calendars.create(year,month,day,hour,minute,second)}

${#calendars.create(year,month,day,hour,minute,second,millisecond)}

/*

* Create a calendar (java.util.Calendar) object for the current date and time

*/

${#calendars.createNow()}

/*

* Create a calendar (java.util.Calendar) object for the current date (time setto 00:00)

*/

${#calendars.createToday()}

三:#numbers:

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Numbers

* ====================================================================

*/

/*

* ==========================

* Formatting integer numbers

* ==========================

*/

/*

* Set minimum integer digits.

* Also works with arrays, lists or sets

*/

${#numbers.formatInteger(num,3)}

${#numbers.arrayFormatInteger(numArray,3)}

${#numbers.listFormatInteger(numList,3)}

${#numbers.setFormatInteger(numSet,3)}

/*

* Set minimum integer digits and thousands separator:

* 'POINT', 'COMMA', 'WHITESPACE', 'NONE' or 'DEFAULT' (by locale).

* Also works with arrays, lists or sets

*/

${#numbers.formatInteger(num,3,'POINT')}

${#numbers.arrayFormatInteger(numArray,3,'POINT')}

${#numbers.listFormatInteger(numList,3,'POINT')}

${#numbers.setFormatInteger(numSet,3,'POINT')}

/*

* ==========================

* Formatting decimal numbers

* ==========================

*/

/*

* Set minimum integer digits and (exact) decimal digits.

* Also works with arrays, lists or sets

*/

${#numbers.formatDecimal(num,3,2)}

${#numbers.arrayFormatDecimal(numArray,3,2)}

${#numbers.listFormatDecimal(numList,3,2)}

${#numbers.setFormatDecimal(numSet,3,2)}

/*

* Set minimum integer digits and (exact) decimal digits, and also decimalseparator.

* Also works with arrays, lists or sets

*/

${#numbers.formatDecimal(num,3,2,'COMMA')}

${#numbers.arrayFormatDecimal(numArray,3,2,'COMMA')}

${#numbers.listFormatDecimal(numList,3,2,'COMMA')}

${#numbers.setFormatDecimal(numSet,3,2,'COMMA')}

/*

* Set minimum integer digits and (exact) decimal digits, and also thousands and

* decimal separator.

* Also works with arrays, lists or sets

*/

${#numbers.formatDecimal(num,3,'POINT',2,'COMMA')}

${#numbers.arrayFormatDecimal(numArray,3,'POINT',2,'COMMA')}

${#numbers.listFormatDecimal(numList,3,'POINT',2,'COMMA')}

${#numbers.setFormatDecimal(numSet,3,'POINT',2,'COMMA')}

/*

* ==========================

* Utility methods

* ==========================

*/

/*

* Create a sequence (array) of integer numbers going

* from x to y

*/

${#numbers.sequence(from,to)}

${#numbers.sequence(from,to,step)}

四:#strings:

/*

* ======================================================================

* See javadoc API for class org.thymeleaf.expression.Strings

* ======================================================================

*/

/*

* Null-safe toString()

*/

${#strings.toString(obj)} // also array*, list* and set*

/*

* Check whether a String is empty (or null). Performs a trim() operation beforecheck

* Also works with arrays, lists or sets

* * Also works with arrays, lists or sets

*/

${#strings.isEmpty(name)}

${#strings.arrayIsEmpty(nameArr)}

${#strings.listIsEmpty(nameList)}

${#strings.setIsEmpty(nameSet)}

/*

* Perform an 'isEmpty()' check on a string and return it if false, defaultingto

* another specified string if true.

* Also works with arrays, lists or sets

*/

${#strings.defaultString(text,default)}

${#strings.arrayDefaultString(textArr,default)}

${#strings.listDefaultString(textList,default)}

${#strings.setDefaultString(textSet,default)}

/*

* Check whether a fragment is contained in a String

* Also works with arrays, lists or sets

*/

${#strings.contains(name,'ez')} // also array*, list* and set*

${#strings.containsIgnoreCase(name,'ez')} // also array*, list* and set*

/*

* Check whether a String starts or ends with a fragment

* Also works with arrays, lists or sets

*/

${#strings.startsWith(name,'Don')} // also array*, list* and set*

${#strings.endsWith(name,endingFragment)} // also array*, list* and set*

/*

* Substring-related operations

* Also works with arrays, lists or sets

*/

${#strings.indexOf(name,frag)} // also array*, list* and set*

${#strings.substring(name,3,5)} // also array*, list* and set*

${#strings.substringAfter(name,prefix)} // also array*, list* and set*

${#strings.substringBefore(name,suffix)} // also array*, list* and set*

${#strings.replace(name,'las','ler')} // also array*, list* and set*

/*

* Append and prepend

* Also works with arrays, lists or sets

*/

${#strings.prepend(str,prefix)} // also array*, list* and set*

${#strings.append(str,suffix)} // also array*, list* and set*

/*

* Change case

* Also works with arrays, lists or sets

*/

${#strings.toUpperCase(name)} // also array*, list* and set*

${#strings.toLowerCase(name)} // also array*, list* and set*

/*

* Split and join

*/

${#strings.arrayJoin(namesArray,',')}

${#strings.listJoin(namesList,',')}

${#strings.setJoin(namesSet,',')}

${#strings.arraySplit(namesStr,',')} // returns String[]

${#strings.listSplit(namesStr,',')} // returns List

${#strings.setSplit(namesStr,',')} // returns Set

/*

* Trim

* Also works with arrays, lists or sets

*/

${#strings.trim(str)} // also array*, list* and set*

/*

* Compute length

* Also works with arrays, lists or sets

*/

${#strings.length(str)} // also array*, list* and set*

/*

* Abbreviate text making it have a maximum size of n. If text is bigger, it

* will be clipped and finished in "..."

* Also works with arrays, lists or sets

*/

${#strings.abbreviate(str,10)} // also array*, list* and set*

/*

* Convert the first character to upper-case (and vice-versa)

*/

${#strings.capitalize(str)} // also array*, list* and set*

${#strings.unCapitalize(str)} // also array*, list* and set*

/*

* Convert the first character of every word to upper-case

*/

${#strings.capitalizeWords(str)} // also array*, list* and set*

${#strings.capitalizeWords(str,delimiters)} // also array*, list* and set*

/*

* Escape the string

*/

${#strings.escapeXml(str)} // also array*, list* and set*

${#strings.escapeJava(str)} // also array*, list* and set*

${#strings.escapeJavaScript(str)} // also array*, list* and set*

${#strings.unescapeJava(str)} // also array*, list* and set*

${#strings.unescapeJavaScript(str)} // also array*, list* and set*

/*

* Null-safe comparison and concatenation

*/

${#strings.equals(first, second)}

${#strings.equalsIgnoreCase(first, second)}

${#strings.concat(values...)}

${#strings.concatReplaceNulls(nullValue, values...)}

/*

* Random

*/

${#strings.randomAlphanumeric(count)}

五:#objects :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Objects

* ====================================================================

*/

/*

* Return obj if it is not null, and default otherwise

* Also works with arrays, lists or sets

*/

${#objects.nullSafe(obj,default)}

${#objects.arrayNullSafe(objArray,default)}

${#objects.listNullSafe(objList,default)}

${#objects.setNullSafe(objSet,default)}

六:#bools :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Bools

* ====================================================================

*/

/*

* Evaluate a condition in the same way that it would be evaluated in a th:iftag

* (see conditional evaluation chapter afterwards).

* Also works with arrays, lists or sets

*/

${#bools.isTrue(obj)}

${#bools.arrayIsTrue(objArray)}

${#bools.listIsTrue(objList)}

${#bools.setIsTrue(objSet)}

/*

* Evaluate with negation

* Also works with arrays, lists or sets

*/

${#bools.isFalse(cond)}

${#bools.arrayIsFalse(condArray)}

${#bools.listIsFalse(condList)}

${#bools.setIsFalse(condSet)}

/*

* Evaluate and apply AND operator

* Receive an array, a list or a set as parameter

*/

${#bools.arrayAnd(condArray)}

${#bools.listAnd(condList)}

${#bools.setAnd(condSet)}

/*

* Evaluate and apply OR operator

* Receive an array, a list or a set as parameter

*/

${#bools.arrayOr(condArray)}

${#bools.listOr(condList)}

${#bools.setOr(condSet)}

七:#arrays :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Arrays

* ====================================================================

*/

/*

* Converts to array, trying to infer array component class.

* Note that if resulting array is empty, or if the elements

* of the target object are not all of the same class,

* this method will return Object[].

*/

${#arrays.toArray(object)}

/*

* Convert to arrays of the specified component class.

*/

${#arrays.toStringArray(object)}

${#arrays.toIntegerArray(object)}

${#arrays.toLongArray(object)}

${#arrays.toDoubleArray(object)}

${#arrays.toFloatArray(object)}

${#arrays.toBooleanArray(object)}

/*

* Compute length

*/

${#arrays.length(array)}

/*

* Check whether array is empty

*/

${#arrays.isEmpty(array)}

/*

* Check if element or elements are contained in array

*/

${#arrays.contains(array, element)}

${#arrays.containsAll(array, elements)}

八:#lists :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Lists

* ====================================================================

*/

/*

* Converts to list

*/

${#lists.toList(object)}

/*

* Compute size

*/

${#lists.size(list)}

/*

* Check whether list is empty

*/

${#lists.isEmpty(list)}

/*

* Check if element or elements are contained in list

*/

${#lists.contains(list, element)}

${#lists.containsAll(list, elements)}

/*

* Sort a copy of the given list. The members of the list must implement

* comparable or you must define a comparator.

*/

${#lists.sort(list)}

${#lists.sort(list, comparator)}

九:#sets :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Sets

* ====================================================================

*/

/*

* Converts to set

*/

${#sets.toSet(object)}

/*

* Compute size

*/

${#sets.size(set)}

/*

* Check whether set is empty

*/

${#sets.isEmpty(set)}

/*

* Check if element or elements are contained in set

*/

${#sets.contains(set, element)}

${#sets.containsAll(set, elements)}

十:#maps :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Maps

* ====================================================================

*/

/*

* Compute size

*/

${#maps.size(map)}

/*

* Check whether map is empty

*/

${#maps.isEmpty(map)}

/*

* Check if key/s or value/s are contained in maps

*/

${#maps.containsKey(map, key)}

${#maps.containsAllKeys(map, keys)}

${#maps.containsValue(map, value)}

${#maps.containsAllValues(map, value)}

十一:#aggregates :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Aggregates

* ====================================================================

*/

/*

* Compute sum. Returns null if array or collection is empty

*/

${#aggregates.sum(array)}

${#aggregates.sum(collection)}

/*

* Compute average. Returns null if array or collection is empty

*/

${#aggregates.avg(array)}

${#aggregates.avg(collection)}

十二:#messages :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Messages

* ====================================================================

*/

/*

* Obtain externalized messages. Can receive a single key, a key plus arguments,

* or an array/list/set of keys (in which case it will return an array/list/setof

* externalized messages).

* If a message is not found, a default message (like '??msgKey??') is returned.

*/

${#messages.msg('msgKey')}

${#messages.msg('msgKey', param1)}

${#messages.msg('msgKey', param1, param2)}

${#messages.msg('msgKey', param1, param2, param3)}

${#messages.msgWithParams('msgKey', new Object[] {param1, param2, param3,param4})}

${#messages.arrayMsg(messageKeyArray)}

${#messages.listMsg(messageKeyList)}

${#messages.setMsg(messageKeySet)}

/*

* Obtain externalized messages or null. Null is returned instead of a default

* message if a message for the specified key is not found.

*/

${#messages.msgOrNull('msgKey')}

${#messages.msgOrNull('msgKey', param1)}

${#messages.msgOrNull('msgKey', param1, param2)}

${#messages.msgOrNull('msgKey', param1, param2, param3)}

${#messages.msgOrNullWithParams('msgKey', new Object[] {param1, param2, param3,param4})}

${#messages.arrayMsgOrNull(messageKeyArray)}

${#messages.listMsgOrNull(messageKeyList)}

${#messages.setMsgOrNull(messageKeySet)}

十三:#ids :

/*

* ====================================================================

* See javadoc API for class org.thymeleaf.expression.Ids

* ====================================================================

*/

/*

* Normally used in th:id attributes, for appending a counter to the idattribute value

* so that it remains unique even when involved in an iteration process.

*/

${#ids.seq('someId')}

/*

* Normally used in th:for attributes in tags, so that theselabels can refer to Ids

* generated by means if the #ids.seq(...) function.

*

* Depending on whether the goes before or after the element withthe #ids.seq(...)

* function, the "next" (label goes before "seq") or the"prev" function (label goes after

* "seq") function should be called.

*/

${#ids.next('someId')}

${#ids.prev('someId')}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,752评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,100评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,244评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,099评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,210评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,307评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,346评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,133评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,546评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,849评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,019评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,702评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,331评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,030评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,260评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,871评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,898评论 2 351

推荐阅读更多精彩内容

  • 来源:https://zhuanlan.zhihu.com/p/20913858Thymeleaf是一款用于渲染X...
    熊熊要更努力阅读 563评论 0 0
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,743评论 0 33
  • 从依恋关系的角度来论证为什么说0-3岁是人生最重要的阶段? 0-3岁的孩子有精神胚胎期,他的情商和社会性是一个开始...
    刘懿凡阅读 249评论 0 0
  • 剧组的戏已经结束了,一向不爱看剧的嘉文破天荒地追完了剧。摄影师把餐馆拍得真美呀,档次真是高大上呀。店里已经美那么...
    杨家有女阅读 380评论 0 0
  • 想想小时候的自我介绍 我姓啥,名啥,今年几岁(虽然至今不会计算自己的年纪)只能默默的报上属相,你自个儿算吧。性感开...
    小吏123阅读 210评论 0 1