2017-01-06 12 views
3

Thymeleaf + Springとフォームの検証を使用して、このフィールドの横にあるフィールドに関連するエラーを表示します。Thymeleaf:フィールドによる検証エラー

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

フィールドにエラーがある場合は、「エラー」クラスが実際に適用されます。しかし、フィールドの検証エラーを表示する簡単な方法はありますか?

答えて

5

使用すると、エラーを表示するには、このコード:あなたの助けのための

<p class="alert alert-danger" th:if="${#fields.hasErrors('companyName')}" th:errors="*{companyName}"></p> 
+0

おかげでたくさん! – Rolintocour

関連する問題