【Springboot集成Neo4j完整版教程】

这篇具有很好参考价值的文章主要介绍了【Springboot集成Neo4j完整版教程】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【Springboot集成Neo4j完整版教程】

🚀 Neo4j 🚀

🌲 算法刷题专栏 | 面试必备算法 | 面试高频算法 🍀
🌲 越难的东西,越要努力坚持,因为它具有很高的价值,算法就是这样✨
🌲 作者简介:硕风和炜,CSDN-Java领域优质创作者🏆,保研|国家奖学金|高中学习JAVA|大学完善JAVA开发技术栈|面试刷题|面经八股文|经验分享|好用的网站工具分享💎💎💎
🌲 恭喜你发现一枚宝藏博主,赶快收入囊中吧🌻
🌲 人生如棋,我愿为卒,行动虽慢,可谁曾见我后退一步?🎯🎯

🚀 Neo4j 🚀

【Springboot集成Neo4j完整版教程】
【Springboot集成Neo4j完整版教程】

🌟 知识回顾

大家根据自己情况的情况自行选择之前的文章进行学习

【Docker安装部署Neo4j保姆级教程】
【使用Neo4j进行图数据可视化】
【Neo4j教程之CQL命令基本使用】
【Neo4j教程之CQL函数基本使用】

🌟 Spring Data Neo4j官方指导手册

Spring Data Neo4j官方指导手册

第一步进入Spring官方,选择SpringData模块
【Springboot集成Neo4j完整版教程】

第二步选择Spring Data Neo4j
【Springboot集成Neo4j完整版教程】
第三步查看Spring Data Neo4j指导手册相关的内容
【Springboot集成Neo4j完整版教程】

🌟 Docker启动Neo4j

注意:此处我们直接通过Docker来启动Neo4j,前面的教程中也有,不会的同学可以先去学习

docker start neo4j 

【Springboot集成Neo4j完整版教程】

🌟 Spring Boot集成Neo4J配置信息

🍤 新创建一个SpringBoot项目

🍤 导入spring-boot-starter-data-neo4j依赖

添加对应的依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

🍤 配置neo4j相关的连接信息

添加对应的配置文件

spring.data.neo4j.uri= bolt://localhost:7687
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=123456

🌟 Spring Boot集成Neo4J案例实操

🍤 创建对应的Person实体信息

import lombok.Data;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;

/**
 * 创作一个对应 Person 实体对象 -> 对应我们 Neo4j数据库中的 Node 对象
 */
@Data
@NodeEntity("Person")
public class Person {

    @Id
    @GeneratedValue
    private Long id;

    @Property
    private String name;
}

🍤 创建对应的Repository接口

import entity.Person;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PersonRepository extends Neo4jRepository<Person,Long> {
}

🍤 创建节点访问测试

代码案例

import dao.PersonRepository;
import entity.Person;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringbootNeo4jApplicationTests {

    @Autowired
    private PersonRepository personRepository;

    @Test
    void contextLoads() {
        Person person = new Person();
        person.setName("硕风和炜");
        personRepository.save(person);
    }
}

访问测试
【Springboot集成Neo4j完整版教程】

🌟 Spring Boot集成Neo4J案例实操2

🍤 创建对应的PersonRelation实体信息

import lombok.Data;
import org.neo4j.ogm.annotation.*;

import java.io.Serializable;

@Data
@RelationshipEntity(type = "徒弟")
public class PersonRelation implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @StartNode
    private Person parent;

    @EndNode
    private Person child;

    @Property
    private String relation;

    public PersonRelation(Person parent, Person child, String relation) {
        this.parent = parent;
        this.child = child;
        this.relation = relation;
    }
}

🍤 Person实体中增加对应的构造方法

import lombok.Data;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;

/**
 * 创作一个对应 Person 实体对象 -> 对应我们 Neo4j数据库中的 Node 对象
 */
@Data
@NodeEntity("Person")
public class Person {

    @Id
    @GeneratedValue
    private Long id;

    @Property
    private String name;

    @Property
    private Integer age;

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}

🍤 创建对应的PersonRelationRepository接口

import com.ljw.springboot.neo4j.entity.PersonRelation;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PersonRelationRepository extends Neo4jRepository<PersonRelation,Long> {

}

🍤 创建节点访问测试

代码案例

import com.ljw.springboot.neo4j.dao.PersonRelationRepository;
import com.ljw.springboot.neo4j.dao.PersonRepository;
import com.ljw.springboot.neo4j.entity.Person;
import com.ljw.springboot.neo4j.entity.PersonRelation;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringbootNeo4jApplicationTests {

    @Autowired
    private PersonRelationRepository personRelationRepository;

    @Test
    void nodeRelation(){
        Person p1 = new Person("唐僧",4321);
        Person p2 = new Person("孙悟空",3421);
        Person p3 = new Person("猪八戒",2413);
        Person p4 = new Person("沙僧",1234);

        PersonRelation pr1 = new PersonRelation(p1,p2,"徒弟");
        PersonRelation pr2 = new PersonRelation(p1,p3,"徒弟");
        PersonRelation pr3 = new PersonRelation(p1,p4,"徒弟");

        personRelationRepository.save(pr1);
        personRelationRepository.save(pr2);
        personRelationRepository.save(pr3);

    }

}

访问测试
【Springboot集成Neo4j完整版教程】

🌟 总结

本文展示了如何使用Neo4J和Spring Boot整合,如何在Spring Boot应用程序中使用Neo4J数据库来持久化数据、使用CQL语言进行高效的查询操作,并提供了一个非常简单的例子以演示如何使用Neo4J数据库。相信通过本文的学习,读者已经掌握了如何使用Neo4J和Spring Boot整合,并且具备将此应用于实际项目的能力。

💬 共勉

最后,我想和大家分享一句一直激励我的座右铭,希望可以与大家共勉!

【Springboot集成Neo4j完整版教程】

【Springboot集成Neo4j完整版教程】文章来源地址https://www.toymoban.com/news/detail-497019.html

到了这里,关于【Springboot集成Neo4j完整版教程】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 图数据库Neo4j——SpringBoot使用Neo4j & 简单增删改查 & 复杂查询初步

    图形数据库是专门用于存储图形数据的数据库,它使用图形模型来存储数据,并且支持复杂的图形查询。常见的图形数据库有Neo4j、OrientDB等。 Neo4j是用Java实现的开源NoSQL图数据库,本篇博客介绍如何在SpringBoot中使用Neo4j图数据库,如何进行简单的增删改查,以及如何进行复杂

    2024年02月06日
    浏览(42)
  • SpringBoot整合Neo4j

    Neo4j是一个高性能的,NOSQL图形数据库,它的内部就是一个高性能的图形引擎,专门为应用程序提供嵌入式,磁盘的高性能存储和遍历图形结构的能力。Spring Boot是一个旨在简化创建独立的,生产级别的Spring基础应用程序的开发框架。在本文中,我们将探讨如何在Spring Boot项目

    2024年02月06日
    浏览(37)
  • spring boot集成neo4j实现简单的知识图谱

    随着社交、电商、金融、零售、物联网等行业的快速发展,现实社会织起了了一张庞大而复杂的关系网,传统数据库很难处理关系运算。大数据行业需要处理的数据之间的关系随数据量呈几何级数增长,急需一种支持海量复杂数据关系运算的数据库,图数据库应运而生。 世界

    2024年03月12日
    浏览(48)
  • springboot整合neo4j模糊查询

    1.场景 查询与content相似的实体 解决方案: 1.直接从neo4j中查询所有实体并使用杰卡德相似度算法计算相似度,返回top n,该方案由于要匹配图中所有实体,性能较差。 2.模糊查询neo4j中的实体,并对查询结果与content做相似度计算,相似度算法为hutool中的TextSimilarity.similar()接口

    2024年02月13日
    浏览(28)
  • neo4j教程-安装部署

    •Neo4j是一个开源的NoSQL图形存储数据库,可为应用程序提供支持ACID的后端。Neo4j的开发始于2003年,自2007年转变为开源图形数据库模型。程序员使用的是路由器和关系的灵活网络结构,而不是静态表,但是可以享受企业级质量数据库的所有好处。与关系数据库索引,对于许多

    2024年02月15日
    浏览(41)
  • Neo4j安装配置教程

    安装所需配件网盘一键下载。 以下描述中,官网下载均有描述,也可自官网下载。 Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中。由于知识图谱中存在大量的关系型信息(实体—关系—实体), 使用结构化数据库进行存储将产生大量的冗余存

    2024年02月14日
    浏览(25)
  • neo4j教程-Cypher操作

    Cypher是图形存储数据库Neo4j的查询语言,Cypher是通过模式匹配Neo4j数据库中的节点和关系,从而对数据库Neo4j中的节点和关系进行一系列的相关操作。 下面,通过一张表来介绍一下常用的Neo4j操作命令及相关说明,具体如表所示。 操作命令 相关说明 CREATE 创建节点、关系 MATC

    2024年02月15日
    浏览(40)
  • springboot整合neo4j-使用原生cypher

    该文的实现有更简单的方式,详见我的另一篇博客springboot整合neo4j–采用Neo4jClient和Neo4jTemplate方式 Neo4j 提供 JAVA API 以编程方式执行所有数据库操作。它支持三种类型的API: 1、Neo4j 原生的 Java API 原生 Java API 是一种低级别的纯 JAVA API,用于执行数据库操作。 2、Neo4j Cypher Jav

    2024年02月12日
    浏览(32)
  • Springboot整合Neo4J图数据库

    1.引入依赖 JDK11, neo4J4.4.23 2.解决springboot与neo4j兼容问题

    2024年02月09日
    浏览(33)
  • Springboot项目连接neo4j数据库

    首先创建一个springboot项目,这里不再介绍。 连接 neo4j 数据库的依赖包 spring-boot-starter-data-neo4j依赖包 mybatis-plus依赖包

    2024年02月12日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包