Hello World 之Spring Boot 调用图数据库Neo4j
时间:2022-03-15 15:03
- 明日歌
- [清]钱鹤滩
- 明日复明日,明日何其多!
- 我生待明日,万事成蹉跎
application.yml版:
- spring:
- data:
- neo4j:
- username: neo4j
- password: helloworld
时间:2022-03-15 15:03
- 明日歌
- [清]钱鹤滩
- 明日复明日,明日何其多!
- 我生待明日,万事成蹉跎
application.yml版:
- spring:
- data:
- neo4j:
- username: neo4j
- password: helloworld
如果要表达Or或者And关系(假设legend有属性level),方法名将会是
findByNameAndLevel(String name,String level)
如果要分页,需要继承PagingAndSortingRepository,而不是CrudRepository 。有关springdata的更多细节,笔者将会在以后的博客中详细介绍。
@SpringBootApplication @EnableNeo4jRepositories public class SpringBootNeo4jApplication { public static void main(String[] args) { SpringApplication.run(SpringBootNeo4jApplication.class, args); } }@RunWith(SpringRunner.class) @SpringBootTest public class SpringBootNeo4jApplicationTests { @Autowired LegendRepo legendRepo; private final static Logger log = LoggerFactory.getLogger(SpringBootNeo4jApplicationTests.class); @Test public void contextLoads() { legendRepo.deleteAll(); Legend yangguo = new Legend("杨过"); Legend dragonGirl = new Legend("小龙女"); Legend guoxiang = new Legend("郭襄"); List<Legend> team = Arrays.asList(yangguo, dragonGirl, guoxiang); log.info("Before linking up with Neo4j..."); //java 8 stream team.stream().forEach(legend -> log.info("\t" + legend.toString())); legendRepo.save(yangguo); legendRepo.save(dragonGirl); legendRepo.save(guoxiang); yangguo = legendRepo.findByName(yangguo.getName()); yangguo.fansWith(dragonGirl); yangguo.fansWith(guoxiang); legendRepo.save(yangguo); dragonGirl = legendRepo.findByName(dragonGirl.getName()); dragonGirl.fansWith(guoxiang); // We already know that dragonGirl is a fan of yangguo legendRepo.save(dragonGirl); // We already know guoxiang fans with yangguo and dragongirl log.info("Look up yangguo‘s fans ..."); log.info(legendRepo.findByName("杨过").toString()); } }运行代码查看日志:
4. Neo4j与Spring boot----一生一代一双人Look up yangguo‘s fans ... Request: MATCH (n:`Legend`) WHERE n.`name` = { `name_0` } WITH n RETURN n,[ [ (n)-[r_f1:`FANS`]-(l1:`Legend`) | [ r_f1, l1 ] ] ], ID(n) with params {name_0=杨过} 杨过‘s fans => [郭襄, 小龙女]
Neo4j在某些场合能发挥自己的优势,而用spring boot的方式,使得neo4j的使用非常简单,自从有了spring boot,生活变得好轻松。
关注spring boot,请继续关注我的博客。
原文地址:https://blog.csdn.net/weixin_41897365/article/details/79835319相关推荐
- xshell怎么连接数据库
- MySQL数据库设计规范(仅供参考)
- SQLServer字符串查找(判断字符串是否含数字或字母)
- MySQL源码安装5.7-CentOS7
- 数据库常用架构和同步工作原理
- Apache HBase 1.7.1 发布,分布式数据库
- SQL Server 数据库分离和附加
- sqlSugar 简单封装及使用案例
- 【MySQL】-索引类型
- mysql的数据类型详解
电脑软件
热门排行
今日推荐
热门手游