基础对象
#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与当前请求关联的
#vars:org.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标记相同的功能
#dates:java.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()}
- #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()}
- #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)}
-
#strings:
String对象的实用方法
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)}