使用 Thymeleaf + Spring 和表单验证,我想显示与该字段旁边的字段相关的错误。
<input type="text"
th:field="*{companyName}" class="form-control"
placeholder="Code client" th:errorClass="'error'"/>
如果该字段有错误,则确实应用“错误”类。但是有没有一种简单的方法来显示字段的验证错误?
最佳答案
使用此代码显示错误:
<p class="alert alert-danger" th:if="${#fields.hasErrors('companyName')}" th:errors="*{companyName}"></p>
关于spring - Thymeleaf:按字段验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41510520/