首页 > 学院 > 开发设计 > 正文

thymeleaf 获取map的值

2019-11-14 10:06:33
字体:
来源:转载
供稿:网友

个人测试的表单验证的返回,使用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>

示例结果:

这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表