【发布时间】:2017-10-18 16:30:59
【问题描述】:
(Spring 应用程序 - MVC) 我用列定义了一个表:
`time` TIME NOT NULL,
在我拥有的实体类中:
@Getter @Setter
@NotNull
private java.sql.Time time;
在我的 DTO 课程中,我有:
@Getter @Setter
private java.sql.Time time;
当我从邮递员那里发送"time": "12:10" 时,我得到:
com.fasterxml.jackson.databind.JsonMappingException: Instantiation of [simple type, class java.sql.Time] value failed: null (through reference chain: (<points to a field (of java.sql.Time) in my aforementioned DTO class>))
当我在 MySQL 中有 TIMESTAMP,在 dto 和实体中有 java LocalTime 时,它可以工作,但它会同时保留时间和日期。我只想有时间。
我浏览了以前的不同主题 f.e. Joda-Time-Hibernate 所以我使用 LocalTime(在 dto 和实体中)和注释 @Type(type="org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime") 但它不起作用。
有人可以帮我吗,dto、实体、表的列的正确类型(仅限时间)是什么,所以杰克逊可以序列化、休眠理解和持久化。
【问题讨论】:
-
你不必使用任何 java.sql.* 类型。