我正在使用带有 spring-data-neo4j-rest 的 spring-boot。Maven依赖项为
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>3.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
我的模型有一个 LocalDateTime 类型的字段
@NodeEntity
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyModel {
@GraphId
private Long id;
private LocalDateTime datetime = LocalDateTime.now();
private Date date = new Date();
...getter/setter
}
在服务类中,此模型使用 Neo4jTemplate 保存方法保存。
@Autowired
Neo4jTemplate template;
public T create(T t) {
T t1 = template.save(t);
return t1;
}
问题是当 Date 字段作为时间戳存储在 Neo4j 中时,LocalDateTime 根本没有存储。不明白我在这里做错了什么。是否需要将 LocalDateTime 的自定义转换器添加到长转换并如LocalDateTime 中所述注册不是转换为字符串而是转换为 Json 对象