泰州网站制作专业,郑州做花店网站,网站建设步骤的论文,wordpress如何显示文章列表1.背景
看了spring-boot-starter-data-neo4j的源码之后发现#xff0c;该starter内已经实现了Neo4jClient和Neo4jTemplate#xff0c;我们只需要使用Autowire就能直接使用它操作neo4j。 Neo4jClient方式与我的另一篇springboot整合neo4j-使用原生cypher Java API博客方式一样…1.背景
看了spring-boot-starter-data-neo4j的源码之后发现该starter内已经实现了Neo4jClient和Neo4jTemplate我们只需要使用Autowire就能直接使用它操作neo4j。 Neo4jClient方式与我的另一篇springboot整合neo4j-使用原生cypher Java API博客方式一样Neo4jTemplate则与SpringBoot 整合 Neo4j博客实现方式类似但比这篇博客要简单。
2.实现
2.1引入maven
springboot版本为2.6低版本的可能不支持。
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-neo4j/artifactId
/dependency该包里面已经包含了neo4j-java-driver故不需要额外引入。 完整maven文件与我的另一篇博客内容一致springboot整合neo4j-使用原生cypher Java API。
2.2配置
因为该方式是springboot starter方式所以配置文件的配置路径是固定的。
spring.data.neo4j.uribolt://127.0.0.1:7687
spring.data.neo4j.usernameneo4j
spring.data.neo4j.password1234562.3测试
package com.win.chaos;import com.win.chaos.model.neo4j.Neo4jGraph;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.*;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.data.neo4j.core.Neo4jTemplate;
import javax.annotation.Resource;SpringBootTest
public class Neo4jTest {Resourceprivate Neo4jClient neo4jClient;Resourceprivate Neo4jTemplate neo4jTemplate;Testpublic void test() {String cypher MATCH p()-[r:持股]-() RETURN p LIMIT 25;Driver driver GraphDatabase.driver(bolt://127.0.0.1:7687, AuthTokens.basic(neo4j, 123456));Session session driver.session();//Transaction ts session.beginTransaction();//Result result ts.run(cypher);Result result session.run(cypher);Neo4jGraph graph Neo4jGraph.parse(result);int size graph.getNodes().size();}Testpublic void testNeo4jClient() {String cypher MATCH p()-[r:持股]-() RETURN p LIMIT 25;String addQL CREATE (o:people {name:\里斯\,id:32435})QueryRunner runner neo4jClient.getQueryRunner();Result result runner.run(cypher);Neo4jGraph graph Neo4jGraph.parse(result);int size graph.getNodes().size();runner.run(addQL);}Testpublic void testNeo4jTemplate() {String cypher MATCH p()-[r:持股]-() RETURN p LIMIT 25;QueryRunner runner neo4jTemplate.findAll();//需要传入参数Result result runner.run(cypher);Neo4jGraph graph Neo4jGraph.parse(result);int size graph.getNodes().size();}
}
上述代码中的解析查询结果的代码Neo4jGraph.parse与我的另一篇博客内容一致springboot整合neo4j-使用原生cypher Java API。
完整代码本博客完整代码