在 thymeleaf 中是否有更好的方法来执行以下操作?
<div th:if="${status} == 404">
Special display for 404 page!
</div>
<div th:if="${status} != 404">
Not a 404 page!
</div>
例如,在 django 中,它很简单:
{% if status == 404 %}
Special display for 404 page!
{% else %}
Not a 404 page!
{% endif %}
最佳答案
来自文档:
Thymeleaf's main goal is to bring elegant natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams.
所以这种类似 HTML 的语法是有意为之的,没有“更简单”的语法。
另请参阅How to do if-else in Thymeleaf?一些替代方案。
关于java - 如果/否则在 thymeleaf 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51550251/