In fact, as long as the form under the form of input labels, write
<P th: if = "$ {# fields.hasErrors ( 'variable name')}" th: errors = "* {variable name}"> </ p>
Examples
1 <p th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></p>
The complete code
. 1 <! DOCTYPE the HTML > 2 < HTML xmlns: TH = "http://www.thymeleaf.org" > . 3 <-! Incoming property xmlns: th = "http://www.thymeleaf.org" to enable thymeleaf template . 4 Thymeleaf corresponds JSP -> . 5 < head > . 6 < title > Add user </ title > . 7 < Meta HTTP-equiv = "the Type-the Content" Content = "text / HTML; charset = UTF-. 8" /> . 8 </ head > . 9 <body> 10 <form th:action="@{/adduser}" th:object="${user}" method="post"> 11 <label for="name">姓名</label> 12 <input type="text" th:field="*{name}" id="name" placeholder="Name"> 13 14 <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></p> 15 16 17 <label for="age">年龄</label> 18 <input type="text" th:field="*{age}" id="age" placeholder="age"> 19 20 <p th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></p> 21 22 23 <label for="email">邮箱</label> 24 <input type="text" th:field="*{email}" id="email" placeholder="Email"> 25 <p th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></p> 26 27 28 <input type="submit" value="保存"> 29 </form> 30 </body> 31 </html>