变量输出与字符串操作
1 th:text
在页面中输出值,如:
<span th:text="${msg}"></span>
2 th:value
可以将一个值放入到input标签的value中,如:
<input type="text" name="username" th:value="${msg}" />
3 ${#strings.isEmpty(key)}
判断字符串是否为空,如果为空返回true,否则返回false,如:
<span th:text="${#strings.isEmpty(msg)}"></span>
Thymeleaf内置对象注意语法:
1、调用内置对象一定要用#;
2、大部分内置对象都以s结尾,如strings、numbers、dates等
4 ${#strings.contains(key, str1)}
判断字符串是否包含指定的字符str1,如果包含返回true,否则返回false,如:
<span th:text="${#strings.contains(msg,'T')}"></span>
5 ${#strings.startsWith(key,str1)}
判断当前字符是否以子串str1开头,如果是返回true,否则返回false,如:
<span th:text="${#strings.startsWith(msg,'T')}"></span>
6 ${#strings.endsWith(key,str1)}
判断当前字符是否以子串str1结尾,如果是返回true,否则返回false,如:
<span th:text="${#strings.endsWith(msg,'例')}"></span>
7 ${#strings.length(key)}
返回字符串的长度,如:
<span th:text="${#strings.length(msg)}"></span>
8 ${#strings.indexOf(key,str1)}
返回子串str1的位置,并返回该子串的下标,如果没找到会返回-1,如:
<span th:text="${#strings.indexOf(msg,'h')}"></span>
9 ${#strings.substring(msg,start,end)或${#strings.substring(msg,end)}
截取子串,用法与jdk类下subString方法相同,如:
<span th:text="${#strings.substring(msg,13)}"></span>
<hr/>
<span th:text="${#strings.substring(msg,13,14)}"></span>
10 ${#strings.toUpperCase(key)}或${#strings.toLowerCase(key)}
字符串大小写转换,如:
<span th:text="${#strings.toUpperCase(msg)}"></span>
<hr/>
<span th:text="${#strings.toLowerCase(msg)}"></span>