现在工作中开始使用Neo4j,但对照网络上的教程,导入starter后,没有@NodeEntity这个注释,所以参考官方文档,开发了一个简单demo
官方文档
简单DEMO
- 导入starter
<!-- neo4j -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
- 创建节点实体和Repository
@Node("Movie")
public class MovieEntity {
@Id
@GeneratedValue
private Long id;
private final String title;
@Property("tagline")
private final String description;
@Relationship(type = "ACTED_IN", direction = Direction.INCOMING)
private List<ActorEntity> actors;
public MovieEntity(String title, String description) {
this.id = null;
this.title = title;
this.description = description;
}
public MovieEntity withId(Long id) {
if (this.id.equals(id)) {
return this;
} else {
MovieEntity newObject = new MovieEntity(this.title, this.description);
newObject.id = id;
return newObject;
}
}
public MovieEntity addActor(ActorEntity actor) {
if (this.actors == null) {
this.actors = new ArrayList<>();
}
this.actors.add(actor);
return this;
}
// getter
// ...
}


3809

被折叠的 条评论
为什么被折叠?



