阅读量:127
Thymeleaf中的th:text属性用于将文本内容显示在HTML元素中。它允许将一个字符串或表达式的计算结果设置为元素的文本内容。th:text属性的值会替换掉元素中原有的文本内容。
例如,下面的代码将会将"Hello, Thymeleaf!"这个字符串作为文本内容显示在
元素中:
<div th:text="'Hello, Thymeleaf!'"></div>
在渲染页面时,Thymeleaf会将th:text属性的值计算为字符串,并将结果替换掉
元素中原有的文本内容。最终的HTML结果将会是:
[removed][removed]
[removed][removed]
[removed][removed]
[removed]
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?0910b1e24e81c0e61462b7a766830fec";
var s = document.getElementsByTagName("script")[0];
s[removed].insertBefore(hm, s);
})();
(function(b,a,e,h,f,c,g,s){b[h]=b[h]||function(){(b[h].c=b[h].c||[]).push(arguments)};
b[h].s=!!c;g=a.getElementsByTagName(e)[0];s=a.createElement(e);
s.src="//s.union.360.cn/"+f+".js";s.defer=!0;s.async=!0;g[removed].insertBefore(s,g)
})(window,document,"script","_qha",340413,false);
[removed]
<div>Hello, Thymeleaf!</div>
th:text还可以使用Thymeleaf的内置对象和表达式来动态生成文本内容。例如,下面的代码将会将Model中的name属性值作为文本内容显示在
元素中:
<div th:text="${name}"></div>
在渲染页面时,Thymeleaf会根据Model中的name属性值计算文本内容,并将结果替换掉
元素中原有的文本内容。
0 赞
0 踩
看了该问题的人还看了