spring - 是百里香叶还是春天的字段对象
问题描述
我看到如下使用 Thymeleaf 和 Spring boot 进行表单验证的内容。
<p th:if="${#fields.hasErrors('datePlanted')}" th:errors="*{datePlanted}">Incorrect date</p>
现在我不明白:这个字段对象来自哪里?这是Spring准备的东西吗?我在这里的某个地方迷路了。
解决方案
您可以查看 thymeleaf 文档https://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#field-errors
<p th:if="${#fields.hasErrors('datePlanted')}" th:errors="*{datePlanted}">Incorrect date</p>
这里的所有标签如 th:if, th: 错误都来自 thymeleaf 模板。这里没有任何东西来自 Spring Boot。因为这是您的应用程序的前端。
让我们输入字段,例如使用 Thymeleaf 并且您正在提交这是字段,然后当您调用 fields.hasErrors 时,它会查看此字段的任何错误。
<input type="hidden" class="form-control" placeholder="Name"
th:field="*{id}" th:value="*{id}" />
推荐阅读
- cassandra-2.0 - 如何将数据从 cassandra 表复制到带有 where claues 的 CSV?
- c# - 检测绑定在按钮上的布尔数组的变化
- php - 如何在循环内再次插入循环然后插入查询
- javascript - 显示数据后添加按钮不显示
- ios - 如何从通知中心删除 MPRemoteCommandCenter
- java - 使用 Jackson 为不同请求对单个实体的不同属性进行 JSON 序列化
- python - NameError:名称“用户名”未在我的表单中定义
- react-native - 无法使用 'Content-Type': 'multipart/form-data' 获得 .post 来工作 Axios React Native
- arrays - 数组中每个“_id”的别名
- grails - grails 升级到 3.3.10 bootrun 上的 TaskExecutionException