Spring thymeleaf中的data-th-text和th:text有什么区别

问题描述 投票:1回答:1

我是春季百里香的新手,我无法区分这两个data-th-textth:text

任何人都可以借助示例来解释差异,以及何时应使用data-th-textth:text

java spring-boot thymeleaf
1个回答
2
投票

两者都做相同的事情,但根据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>
© www.soinside.com 2019 - 2024. All rights reserved.