天天看点

Thymeleaf文本连接和文字替换

文本连接

无论是什么形式的文本:字面量'...',变量表达式求值或消息表达式求值的结果,都可以用'+'进行连接

th:text="'The name of the user is ' + ${user.name}"

1

文字替换

文字替换可以方便的格式化包含变量的字符串,而无需使用文本连接'...' + '...'。

文字替换的语法为| text substituion demo ${varialble} |

<span th:text="|Welcome to our application, ${user.name}!|">

1

等效于

<span th:text="'Welcome to our application, ' + ${user.name} + '!'">

1

文字替换本身可以和与其他表达式联合使用

<span th:text="${onevar} + ' ' + |${twovar}, ${threevar}|">

1

但是|...|本身中只能包括变量表达式${},不能有其他表达式,比如文本字面量'...', 条件表达式等。

上一篇: 人的需求

继续阅读