首页 / NEO4J / 12.整合neo4j
12.整合neo4j
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了12.整合neo4j,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4756字,纯文字阅读大概需要7分钟。
内容图文
![12.整合neo4j](/upload/InfoBanner/zyjiaocheng/1307/5b6a5cab10bf4bf898b970b0cb95bf1b.jpg)
neo4j
官网下载:https://neo4j.com/download-center/#community
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);
}
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());
}
}
import com.app.SpringDemoApp;
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;
@SpringBootTest(classes = SpringDemoApp.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void test1(){
UserNode userNode = new UserNode();
userNode.setNodeId(1L);
userNode.setUserId("001");
userNode.setName("张三");
userNode.setAge("25");
userService.addUserNode(userNode);
}
}
原文:https://www.cnblogs.com/fly-book/p/11619609.html
内容总结
以上是互联网集市为您收集整理的12.整合neo4j全部内容,希望文章能够帮你解决12.整合neo4j所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。