一、th:text 和 th:utext 有什么作用?
1.相同点
1.都可以对变量或表达式进行求值
2.用“ + ”可进行文本连接
2.不同点
当获取从后段传来的参数带有html标签时,th:text 不会进行解析,th:utext 会进行解析。
二、使用详解
1.文本文字的显示
实例:
<div th:text="hello">world</div>
<div th:utext="hello">world</div>
结果:
hello
hello
2.表达式进行求值
实例:
<div th:text="2>1"></div>
<div th:utext="2>1"></div>
结果:
true
true
3.文本文字拼接
实例:
<div th:text="'hello ' + 'world'"></div>
<div th:utext="'hello ' + 'world'"></div>
结果:
hello world
hello world
4.变量中文字带有Html标签
实例:
msg = "<span>hello world</span>";
<div th:text="${msg}"></div>
<div th:utext="${msg}"></div>
结果:
<span>hello world</span>
hello world