我是春季百里香的新手,我无法区分这两个data-th-text
和th:text
。
任何人都可以借助示例来解释差异,以及何时应使用data-th-text
和th:text
?
两者都做相同的事情,但根据thymeleaf docs:
我们以
th:*
格式使用的非标准属性是HTML5规范所不允许的。为了使模板成为HTML5有效的模板,请在属性名称中使用data-
前缀,并使用hyphen (-)
分隔符代替semi-colons (:)
参考:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#using-texts
这不是HTML5有效:
<p th:text="#{home.welcome}">Welcome to our grocery store!</p>
这是HTML5有效期:
<p data-th-text="#{home.welcome}">Welcome to our grocery store!</p>