SpringBoot整合Neo4j的简单demo

现在工作中开始使用Neo4j,但对照网络上的教程,导入starter后,没有@NodeEntity这个注释,所以参考官方文档,开发了一个简单demo
官方文档

简单DEMO

  1. 导入starter
	<!-- neo4j -->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-neo4j</artifactId>
	</dependency>
  1. 创建节点实体和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
    // ...
}

                
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值