12.整合neo4j
neo4j
官网下载:
https://neo4j.com/download-center/#community
教程:
http://neo4j.com.cn/public/cypher/default.html
bin下运行neo4j.bat console
在浏览器地址栏里输入http://localhost:7474
默认会跳转到 http://localhost:7474/browser
刚开始时,会弹出登录页面,默认的初始密码是neo4j,登录进去后会让你设置新的密码,设完后进入neo4j管理界面
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
spring.data.neo4j.uri=http://localhost:7474
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=123123
@MapperScan("com.fly.Mapper")
@EnableNeo4jRepositories(basePackages = "com.fly.UserDao")
public class SpringDemoApp{
package com.fly.pojo;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;
@NodeEntity(label = "User")
public class UserNode {
@GraphId
private Long nodeId;
@Property
private String userId;
@Property
private String name;
@Property
private String age;
public Long getNodeId() {
return nodeId;
}
public void setNodeId(Long nodeId) {
this.nodeId = nodeId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
package com.fly.pojo;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;
@RelationshipEntity(type = "UserRelation")
public class UserRelation {
@GraphId
private Long id;
@StartNode
private UserNode startNode;
@EndNode
private UserNode endNode;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public UserNode getStartNode() {
return startNode;
}
public void setStartNode(UserNode startNode) {
this.startNode = startNode;
}
public UserNode getEndNode() {
return endNode;
}
public void setEndNode(UserNode endNode) {
this.endNode = endNode;
}
}
package com.fly.UserDao;
import com.fly.pojo.UserRelation;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface UserRelationRepository extends GraphRepository<UserRelation> {
@Query("match p=(n:User)<-[r:UserRelation]->(n1:User) where n.userId={firstUserId} and n1.userId={secondUserId} return p")
List<UserRelation> findUserRelationsByEachId(@Param("firstUserId")String firstUserId,@Param("secondUserId")String secondUserId);
@Query("match (fu:User),(su:User) where fu.userId={firstUserId} and su.userId={secondUserId} create p=(fu)-[r:UserRelation]->(su) return p")
List<UserRelation> addUserRelation(@Param("firstUserId")String firstUserId,@Param("secondUserId")String secondUserId);
}
package com.fly.UserDao;
import com.fly.pojo.UserNode;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface UserRepository extends GraphRepository<UserNode> {
@Query("MATCH (n:User) RETURN n")
List<UserNode> getUserNodeList();
@Query("create (n:User{age:{age},name:{name}}) RETURN n")
List<UserNode> addUserNodeList(@Param("age")String age,@Param("name")String name);
@Query("create (n:User{age:{age},name:{name},userId:{userId}}) RETURN n")
List<UserNode> addUserNodeList(@Param("age")String age,@Param("name")String name,@Param("userId")String userId);
}
package com.fly.service;
import com.fly.UserDao.UserRepository;
import com.fly.pojo.UserNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public void addUserNode(UserNode userNode){
userRepository.addUserNodeList(userNode.getAge(),userNode.getName());
}
public List<UserNode> getUserNodeList(){
return userRepository.getUserNodeList();
}
}
import com.app.SpringDemoApp;
import com.fly.UserDao.UserRelationRepository;
import com.fly.pojo.UserNode;
import com.fly.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
@SpringBootTest(classes = SpringDemoApp.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Autowired
private UserRelationRepository userRelationRepository;
@Test
public void test1(){
UserNode userNode = new UserNode();
userNode.setNodeId(1L);
userNode.setUserId("001");
userNode.setName("张三儿");
userNode.setAge("25");
UserNode userNode2 = new UserNode();
userNode2.setNodeId(2L);
userNode2.setUserId("002");
userNode2.setName("李四儿");
userNode2.setAge("24");
userService.addUserNode(userNode);
userService.addUserNode(userNode2);
}
@Test
public void test2(){
List<UserNode> userNodeList = userService.getUserNodeList();
for (UserNode userNode : userNodeList) {
System.out.printf(userNode.getUserId());
}
}
@Test
public void test3(){
userRelationRepository.addUserRelation("001","002");
}
}
12.整合neo4j的更多相关文章
- 凭借SpringBoot整合Neo4j,我理清了《雷神》中错综复杂的人物关系
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. 哈喽大家好啊,我是Hydra. 虽然距离中秋放假还要熬过漫长的两天,不过也有个好消息,今天是<雷神4>上线Disney+流媒体的日子 ...
- hbase0.96与hive0.12整合高可靠文档及问题总结
本文链接:http://www.aboutyun.com/thread-7881-1-1.html 问题导读:1.hive安装是否需要安装mysql?2.hive是否分为客户端和服务器端?3.hive ...
- springBoot(12)---整合Swagger2
Spingboot整合Swagger2 随着互联网技术的发展,一般开发都是前后端分离,那么前端和后端的唯一联系,变成了API接口:API文档变成了前后端开发人员联系的纽带,变得越来越重要,没有API ...
- Spring Boot:Boot2.0版本整合Neo4j
前面介绍了Boot 1.5版本集成Neo4j,Boot 2.0以上版本Neo4j变化较大. 场景还是电影人员关系 Boot 2.0主要变化 GraphRepository在Boot2.0下不支持了,调 ...
- springboot整合neo4j
刚开始按网上博客搭建 spring boot 和 neo4j一直报sessionFactory找不到,直到下载了spring-data-neo4j的实例demo对比才搭建成功,而且用户名是neo4j, ...
- Hadoop2.2.0 hive0.12 hbase0.94 配置问题记录
环境:centos6.2 Hadoop2.2.0 hive0.12 hbase0.94 1>hadoop配好之后,跑任务老失败,yarn失败,报out of memory错误,然后怎么调整内存大 ...
- 图形数据库 Neo4j 开发实战
https://www.ibm.com/developerworks/cn/java/j-lo-neo4j/ Neo4j 是一个高性能的 NoSQL 图形数据库.Neo4j 使用图(graph)相关的 ...
- Neo4j 因果集群搭建及neo4j-java-driver连接
搭建Neo4j因果集群 1.下载企业版,当前是3,5,9版本 https://neo4j.com/download-center/#enterprise 2.配置,三个核心集群为例 配置文件,conf ...
- Neo4j应用
CQL函数 1. 字符串函数 功能 描述 UPPER 将所有字母改为大写 LOWER 将所有字母改为小写 SUBSTRING 将获取指定范围的子字符串 REPLACE 替换一个字符串的子字符串 mat ...
随机推荐
- sqlserver库相关-表相关-3
原文: https://www.cnblogs.com/wlx520/p/4684441.html 库相关 建库 --创建School数据库之前:首先判断数据库是否存在,若存在则删除后再创建,若不存在 ...
- 42 Bing Search Engine Hacks
42 Bing Search Engine Hacks November 13, 2010 By Ivan Remember Bing, the search engine Microsoft lau ...
- 用SPSS做时间序列
用SPSS做时间序列 关于时间序列,有好多软件可以支持分析,大家比较熟悉的可能是EVIEWS.SPSS.还有STATA,具体用啥软件,结果都是一样的,但是SPSS作为一款学习简单,使用容易的软件还是值 ...
- 修改linux文件的mtime
一. Linux 文件个时间信息 所有Unix 文件系统中的文件或文件夹有三个时间戳,分别为atime.ctime和mtime. atime 表示最后一次访问(仅仅访问,没有改动)文件的时间: mt ...
- MySQL 查询语句--------------进阶5:分组查询
#进阶5:分组查询 /* select 分组函数,列(要求出现在group by的后面) from 表 [where 筛选条件] group by 分组的列表 [order by 子句] 注意: 查询 ...
- mybatis中Oracle分页语句的写法
最近一段时间使用oracle数据库查询分页, 用的是springboot. Oracle数据库中没有像mysql中limit的写法, 只能换其他方式写. 考虑到oracle中的ROWNUM变量, 使用 ...
- 批量更新:A表数据源 B表目标
update a set a.Title = b.Title from Table_A a ,Tbale_B b where a.ID_Table_B = b.ID
- c语言1博客作业12-学期总结
一.我学到的内容 二.收获总结 2.1我的收获 链接: c语言1博客作业01:https://www.cnblogs.com/dy-985211/p/11578914.html c语言1博客作业02: ...
- hibernate validator参数校验&自定义校验注解
参数校验:简单的就逐个手动写代码校验,推荐用Valid,使用hibernate-validator提供的,如果参数不能通过校验,报400错误,请求格式不正确: 步骤1:在参数对象的属性上添加校验注解如 ...
- Spring Boot静态资源
1.4 SpringBoot静态资源 1.4.1 默认静态资源映射 Spring Boot 对静态资源映射提供了默认配置 Spring Boot 默认将 /** 所有访问映射到以下目录: classp ...