【发布时间】:2017-10-11 15:17:20
【问题描述】:
我实际上有两个问题。两者都发生在相同的情况下,如下:
我正在使用 spring 和 thymeleaf,我想向服务器发布一个表单,它工作正常,但服务器无法将一些提交的数据转换为我的 bean 的属性类型。
形式:
<form th:action="@{/demo}}" th:object="${myBean}" method="post">
<label>date</label>
<input type="date" th:field="*{date}">
<label>type</label>
<select th:filed="*{type}">
<option th:each="type: ${types}" th:value="${type.id}" th:text="${type.name}"></option>
</select>
<button type="submit">Submit</button>
</form>
bean定义:
@lombok.Data
public class MyBean{
private ZonedDateTime date;
private MyType type;
}
问题:
- 日期输入的值无法转换为 java.time.ZonedDateTime
- 选择的值(将作为数字发布)无法转换为 MyType 类型的对象。因为 MyType 是一个 JPA 实体,并且为它定义了一个
org.springframework.data.repository.CrudRepository,所以我会对此进行扩展。
如果有人能帮助我,我会很高兴。
【问题讨论】:
标签: spring spring-mvc spring-data-jpa thymeleaf java-time