• #strings字符串对象
    • 转换为字符串
    • 字符串长度
    • 空或null
    • 包含
    • 截取
    • 大小写
    • 拼接追加
    • 去空白
    • 随机生成
    • HtmlEscape编码

#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方法对参数进行编码,返回值&lt;span&gt;hello&lt;/span&gt;
<div th:text="${#strings.escapeXml('<span>hello</span>')}"></div>

Thymeleaf #strings对象相关推荐

  1. Thymeleaf 中文文档----全译版

    文章目录 1 引入Thymeleaf 1.1 Thymeleaf是什么? 1.2 Thymeleaf可以处理什么样的模板? 1.3 方言:标准方言 2 一个很棒的虚拟杂货店设计 2.1 一个杂货店的网 ...

  2. Thymeleaf 教程:使用Thymeleaf[转自官方]

    目录 1介绍Thymeleaf 2 The Good Thymes虚拟杂货店 3使用文本 4标准表达式语法 5设置属性值 6迭代 7条件评估 8模板布局 9局部变量 10属性优先级 11评论和块 12 ...

  3. 模板引擎Thymeleaf(一文让你理解Thymeleaf)

    一.Thymeleaf (一)模板引擎 模板引擎,是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档.使用模板引擎的目的就是为了 ...

  4. 模板引擎 Thymeleaf 语法

    模板引擎 Thymeleaf 1. Thymeleaf 简介 Thymeleaf[taɪm lif],百里香叶,是一个流行的模板引擎,该模板引擎采用 Java 语言开发.Java 中常见的模板引擎有 ...

  5. Thymeleaf中文文档

    文章目录 1 引入Thymeleaf 1.1 Thymeleaf是什么? 1.2 Thymeleaf可以处理什么样的模板? 1.3 方言:标准方言 2 一个很棒的虚拟杂货店设计 2.1 一个杂货店的网 ...

  6. springboot2.0+thymeleaf技术-入门

    文章目录 1.什么thymeleaf? 2.thymeleaf的特点 3.项目创建 thymeleaf手动配置 3.1导入相关包 3.2 thymeleaf视图层文件存放目录 3.3 实现 3.3.1 ...

  7. SpringBoot2.x 集成 Thymeleaf

    本文主要对SpringBoot2.x集成Thymeleaf及其常用语法进行简单总结,其中SpringBoot使用的2.4.5版本. 一.Thymeleaf简介 Thymeleaf是面向Web和独立环境 ...

  8. Thymeleaf模板

    目录 Thymeleaf介绍 Thymeleaf常用设置 Thymeleaf使用 标准变量表达式 选择变量表达式 链接表达式 Thymeleaf属性 th:each循环 if判断 switch判断 t ...

  9. Spring MVC和Thymeleaf:如何从模板访问数据

    在典型的Spring MVC应用程序中, @Controller类负责使用数据准备模型映射并选择要呈现的视图. 该model map允许视图技术的完整抽象,对于Thymeleaf而言,它被转换为Thy ...

最新文章

  1. WCF入门(八)——异常处理2
  2. vmware不能和主机相连
  3. FZU - 2218 Simple String Problem(状压dp)
  4. VScode 1.4新版功能
  5. 服务端 https和SSL
  6. [HAOI2008]玩具取名
  7. 根据工序画出aoe网_这些金刚网纱窗竟然含“毒”!选错就得病
  8. MySQL保留关键字
  9. 2017.10.9 放棋子 思考记录
  10. 分布式大数据多维数据分析(olap)引擎kylin[转]
  11. web3j通过命令行工具新建钱包、更新钱包密码及转账
  12. Apache Flink 在 bilibili 的多元化探索与实践
  13. 非合作博弈篇——纳什均衡(Nash Equilibrium)
  14. 如何恢复删除的文件?wps文件恢复,4种方法教你找回来
  15. PPT文件的密码如何破解掉
  16. 联通校园网不能开热点问题解决办法
  17. VSCode软件介绍
  18. 小白对于Linux的学习
  19. A Game of Thrones(104)
  20. 强大的strace命令

热门文章

  1. vue动画库-Animate.css的使用以及部分问题
  2. 编写Shell程序,通过编写完成compress1、decompress1函数,选择“压缩”或“解压”以及输入文件名,来自动完成文件的压缩、解压过程。
  3. sed 流编辑器 简介及原理
  4. 将dwg图纸中的块切出来进行保存
  5. VLAN间路由-单臂路由
  6. 太吾绘卷加载不进去_太吾绘卷捉蛐蛐办法 怎么捉高品质蛐蛐[多图]
  7. chrome插件开发:为页面添加点击事件
  8. 什么是 Web 应用里加载 google font 带来的 FOIT 和 FOUT 问题?
  9. 外网系统怎么访问协同oa?快解析内网端口映射公网
  10. Possibly consider using a shorter maxLifetime value.