Thymeleaf 常用字符串函数

几乎涵盖了所有的常用字符串函数

运用于判断表达式中时,关系判断使用 gt / ge / eq / lt / le / ne (即:使用缩写)
    
    gt:     great than(大于)> ge:    great equal(大于等于)>= eq:   
    equal(等于)== lt:    less than(小于)< le:    less equal(小于等于)<= ne:   
    not equal(不等于)!=
    
    三元运算<td th:text="${emp.gender}==0?'女':'男'"></td>
    
    
    
    thymeleaf 字符串处理 调用参数的toString方法返回字符串 
    <div th:text="${#strings.toString('hello')}"></div> 返回字符串的长度 
    <div th:text="${#strings.length('hello')}"></div> 判断是否为空或null 
    <div th:text="${#strings.isEmpty('hello')}"></div> 
    <div th:text="${#strings.isEmpty('')}"></div> 
    <div th:text="${#strings.isEmpty(null)}"></div> 为空或null时设置默认值 
    <div th:text="${#strings.defaultString('hello','a')}"></div> 
    <div th:text="${#strings.defaultString('','b')}"></div> 
    <div th:text="${#strings.defaultString(null,'c')}"></div> 判断是否包含(区分大小写)
    <div th:text="${#strings.replace('<span>','span','b')}"></div> 将内容中的span替换为b 
	<div th:text="${#strings.contains('hello','he')}"></div> 
	<div th:text="${#strings.contains('hello','HE')}"></div> 判断是否包含(忽略大小写)
    <div th:text="${#strings.containsIgnoreCase('hello','he')}"></div>
    <div th:text="${#strings.containsIgnoreCase('hello','HE')}"></div>
    判断开头和结尾是否包含(区分大小写) 
    <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) 
    <div th:text="${#strings.indexOf('hello','el')}"></div> 
    <div th:text="${#strings.indexOf('hello','ee')}"></div>
    指定开始和结束索引,截取字符串(如果索引超过字符串长度,则抛出异常) 
    <div th:text="${#strings.substring('hello',1,3)}"></div>
    指定从某个字符串后面截取字符串(如果不包含则返回空字符串) 
    <div th:text="${#strings.substringAfter('hello','e')}"></div> 
    <div th:text="${#strings.substringAfter('hello','ee')}"></div>
    指定从某个字符串前面截取字符串(如果不包含则返回空字符串) 
    <div th:text="${#strings.substringBefore('hello','e')}"></div> 
    <div th:text="${#strings.substringBefore('hello','ee')}"></div> 替换字符串
    <div th:text="${#strings.replace('hello','e','a')}"></div> 转换为大写
    <div th:text="${#strings.toUpperCase('hello')}"></div> 转换为小写 
    <div th:text="${#strings.toLowerCase('HELLO')}"></div> 首字母转换为大写 
    <div th:text="${#strings.capitalize('hello')}"></div> 首字母转换为小写 
    <div th:text="${#strings.unCapitalize('heLLo')}"></div> 每个单词的首字母转为大写 
    <div th:text="${#strings.capitalizeWords('hello world')}"></div>根据分隔符将每个单词的首字母转换为大写 
    <div th:text="${#strings.capitalizeWords('hello-world','-')}"></div>字符串前面追加 
    <div th:text="${#strings.prepend('world','hello ')}"></div>字符串后面追加 
    <div th:text="${#strings.append('hello',' world')}"></div>
    拼接字符串(参数个数不限) 
    <div th:text="${#strings.concat('hello',' world','
    !')}"></div> 从第二个参数之后拼接字符串,如果参数为null,则用第一个参数替代 
    <div th:text="${#strings.concatReplaceNulls('*','hello',null,'world')}"></div>删除空白 
    <div th:text="${#strings.trim(' hello ')}"></div>
    字符串截取指定长度(最小为3),后面加... 
    <div th:text="${#strings.abbreviate('hello,world', 8)}"></div>
    产生指定位数的随机字母数字,范围为大写英文字母加0-9数字 
    <div th:text="${#strings.randomAlphanumeric(4)}"></div>
    调用HtmlEscape类的escapeHtml4Xml方法对参数进行编码 
    <div th:text="${#strings.escapeXml('<span>hello</span>')}"></div> 时间格式化
    <div th:text="${#dates.format(user.date,'yyyy-MM-dd')}">4564546</div>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值