个人测试的表单验证的返回,使用errorMap存放错误信息
<form class="form-signin" action="/login" method="POST">
<!--<p th:each="attr : ${#request.getAttributeNames()}"-->
<!--th:text="${attr} +':'+${#request.getAttribute(attr)}"> 如果你想知道request中有什么属性</p>-->
<p th:text="${#request.getAttribute('errorMap')}"> errorMap中有什么属性</p>
<input type="text" name="username" class="form-control" placeholder="用户名" autofocus
th:class="'field-error form-control'" th:value="${usernameInput}">
<label class="error-label" th:if="${errorMap}" th:text="${errorMap['username']}"></label>
<input type="password" name="password" class="form-control" placeholder="密码"
th:class="'field-error form-control'" th:value="${passwordInput}">
<label class="error-label" th:if="${errorMap}" th:text="${errorMap['password']}"></label>
<input type="text" name="validateCode" class="form-control" placeholder="验证码" th:class="'field-error'" >
<img src="/validateCode">
<label class="error-label" th:if="${errorMap}" th:text="${errorMap['validateCodeError']}"></label>
<button class="btn btn-lg btn-login btn-block" type="submit">
<i class="fa fa-check"></i>
</button>
</form>
示例结果:
版权声明:本文为caimengyuan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。