我习惯编写这样的模板:
<div class="person">
${name}
</div>
这对我来说似乎更具可读性,因为我可以看到标签本身之外的变量。目前在 thymeleaf 中,我需要做:
<div class="person" th:text="${name}" />
或者:
<div class="person" th:text="${name}">
${name} // this text will be replaced and doesn't matter
</div>
有没有办法像我在顶部那样输入变量?
最佳答案
当然,您可以使用expression inlining为此。
<div class="person">
[[${name}]]
</div>
在我链接的文档中,确实讨论了使用表达式内联与自然模板。在大多数情况下,我个人更喜欢自然模板。
关于java - thymeleaf 的可读性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51143731/