#strings字符串对象
转换为字符串
调用参数的toString方法返回字符串,返回值hello
<div th:text="${#strings.toString('hello')}"></div>
字符串长度
返回字符串的长度,返回值5
<div th:text="${#strings.length('hello')}"></div>
空或null
判断是否为空或null,返回值false,true,true
<div th:text="${#strings.isEmpty('hello')}"></div>
<div th:text="${#strings.isEmpty('')}"></div>
<div th:text="${#strings.isEmpty(null)}"></div>
为空或null时设置默认值,返回值hello,b,c
<div th:text="${#strings.defaultString('hello','a')}"></div>
<div th:text="${#strings.defaultString('','b')}"></div>
<div th:text="${#strings.defaultString(null,'c')}"></div>
包含
判断是否包含(区分大小写),返回值true,false
<div th:text="${#strings.contains('hello','he')}"></div>
<div th:text="${#strings.contains('hello','HE')}"></div>
判断是否包含(忽略大小写),返回值true,true
<div th:text="${#strings.containsIgnoreCase('hello','he')}"></div>
<div th:text="${#strings.containsIgnoreCase('hello','HE')}"></div>
判断开头和结尾是否包含(区分大小写),返回值true,false,false,true
<div th:text="${#strings.startsWith('hello','he')}"></div>
<div th:text="${#strings.startsWith('hello','HE')}"></div>
<div th:text="${#strings.startsWith('hello','el')}"></div>
<div th:text="${#strings.endsWith('hello','lo')}"></div>
获取字符串的索引(如果不存在返回-1),返回值1,-1
<div th:text="${#strings.indexOf('hello','el')}"></div>
<div th:text="${#strings.indexOf('hello','ee')}"></div>
截取
指定开始和结束索引,截取字符串(如果索引超过字符串长度,则抛出异常),返回值el
<div th:text="${#strings.substring('hello',1,3)}"></div>
指定从某个字符串后面截取字符串(如果不包含则返回空字符串),返回值llo,空字符串
<div th:text="${#strings.substringAfter('hello','e')}"></div>
<div th:text="${#strings.substringAfter('hello','ee')}"></div>
指定从某个字符串前面截取字符串(如果不包含则返回空字符串),返回值h,空字符串
<div th:text="${#strings.substringBefore('hello','e')}"></div>
<div th:text="${#strings.substringBefore('hello','ee')}"></div>
替换字符串,返回值hallo
<div th:text="${#strings.replace('hello','e','a')}"></div>
大小写
转换为大写,返回值HELLO
<div th:text="${#strings.toUpperCase('hello')}"></div>
转换为小写,返回值hello
<div th:text="${#strings.toLowerCase('HELLO')}"></div>
首字母转换为大写,返回值Hello
<div th:text="${#strings.capitalize('hello')}"></div>
首字母转换为小写,返回值heLLo
<div th:text="${#strings.unCapitalize('heLLo')}"></div>
每个单词的首字母转为大写,返回值HELLO WORD
<div th:text="${#strings.capitalizeWords('hello world')}"></div>
根据分隔符将每个单词的首字母转换为大写,返回值Hello-Word
<div th:text="${#strings.capitalizeWords('hello-world','-')}"></div>
拼接追加
字符串前面追加,返回值hello world
<div th:text="${#strings.prepend('world','hello ')}"></div>
字符串后面追加,返回值hello world
<div th:text="${#strings.append('hello',' world')}"></div>
拼接字符串(参数个数不限),返回值hello world !
<div th:text="${#strings.concat('hello',' world',' !')}"></div>
从第二个参数之后拼接字符串,如果参数为null,则用第一个参数替代,返回值hello*world
<div th:text="${#strings.concatReplaceNulls('*','hello',null,'world')}"></div>
字符串截取指定长度(最小为3),后面加... ,返回值hello...
<div th:text="${#strings.abbreviate('hello,world', 8)}"></div>
去空白
删除空白,返回值hello
<div th:text="${#strings.trim(' hello ')}"></div>
随机生成
产生指定位数的随机字母数字,范围为大写英文字母加0-9数字,返回值RBTA
<div th:text="${#strings.randomAlphanumeric(4)}"></div>
HtmlEscape编码
调用HtmlEscape类的escapeHtml4Xml方法对参数进行编码,返回值<span>hello</span>
<div th:text="${#strings.escapeXml('<span>hello</span>')}"></div>