Thymeleaf变量

时间:2017-03-10 22:21:15

标签: html thymeleaf

有没有办法告诉Thymeleaf,如果任何字段有错误,请显示错误消息?

我目前正在单独列出它们:

<div th:if="${#fields.hasErrors('password')}" th:errors="*{password}" class="validation-message alert alert-danger" role="alert"></div>
<div th:if="${#fields.hasErrors('lastName')}" th:errors="*{lastName}" class="validation-message alert alert-danger" role="alert"></div>
<div th:if="${#fields.hasErrors('firstName')}" th:errors="*{firstName}" class="validation-message alert alert-danger" role="alert"></div>

1 个答案:

答案 0 :(得分:3)

http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#all-errors

应该可以做类似的事情:

<div th:each="err : ${#fields.errors('*')}" class="validation-message alert alert-danger" role="alert" th:text="${err}" />