首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Thymeleaf变量

Thymeleaf变量
EN

Stack Overflow用户
提问于 2017-03-11 06:21:15
回答 1查看 251关注 0票数 0

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

我现在将它们单独列出,如下所示:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2017-03-11 06:36:03

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

应该能够做一些类似的事情:

代码语言:javascript
复制
<div th:each="err : ${#fields.errors('*')}" class="validation-message alert alert-danger" role="alert" th:text="${err}" />
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42728692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档