【发布时间】:2017-07-24 22:28:09
【问题描述】:
我正在尝试使用表单中的单独输入来获取日期和时间。 到目前为止,获取日期是有效的,但是使用获取时间(小时和分钟) 导致错误。 这是我的实体类的一部分:
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date start_date;
@Temporal(TemporalType.TIME)
@DateTimeFormat(pattern = "HH:mm")
private Date start_hour;
这是我用来从用户那里获取数据的表单部分:
<div class="row">
<div class="col-6">
<label th:attr="for='start_date_'+${subject.id}">Start Date</label>
<input class="form-control" type="date" th:attr="id='start_date_'+${subject.id}" th:field="*{start_date}"/>
</div>
<div class="col-6">
<label th:attr="for='start_time_'+${subject.id}">Start hour</label>
<input class="form-control" type="time" th:attr="id='start_time_'+${subject.id}" th:field="*{start_hour}"/>
</div>
</div>
我不断收到错误:
There was an unexpected error (type=Bad Request, status=400).
Validation failed for object='lesson'. Error count: 1
我分别测试了日期输入和时间输入,是时间输入给我带来了麻烦。
【问题讨论】:
-
查看@InitBinder文档,对解决你的问题很有帮助
标签: spring spring-boot thymeleaf