Thymeleaf:字段验证错误

Rol*_*our 3 forms validation spring thymeleaf

使用Thymeleaf + Spring和表单验证,我想显示与此字段旁边的字段相关的错误.

<input type="text"
  th:field="*{companyName}" class="form-control"
  placeholder="Code client" th:errorClass="'error'"/>
Run Code Online (Sandbox Code Playgroud)

如果该字段有错误,则确实应用了类"错误".但有没有一种简单的方法来显示该字段的验证错误?

小智 5

使用此代码显示错误:

<p class="alert alert-danger" th:if="${#fields.hasErrors('companyName')}" th:errors="*{companyName}"></p>
Run Code Online (Sandbox Code Playgroud)