原生API
待补充。。。
SpringBoot整合Neo4j
参考文章来源:https://www.toymoban.com/news/detail-596313.html
- Springboot集成Neo4j_喝醉的咕咕鸟的博客-CSDN博客
- SpringBoot 整合 Neo4j_springboot neo4j_$懒小猿$的博客-CSDN博客
- spring-boot集成neo4j - 知乎
- 【最新】Neo4j官方建议Spring Boot 2.4.及以上版本用Neo4j Java Driver代替The Spring Boot starter_spring boot_学到一寸是一寸-华为云开发者联盟
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-Neo4j</artifactId>
</dependency>
配置
spring:
data:
neo4j:
uri: bolt://127.0.0.1:7687
username: neo4j
password: neo4j
类似于jpa
模式,同样是构建 model 层、repository 层,然后在此基础上操作自定义或模板方法。文章来源地址https://www.toymoban.com/news/detail-596313.html
实体类
节点
@Data
@NodeEntity(label = "Person")
public class Node {
@Id
@GeneratedValue
private Long id;
@Property(name = "name")
private String name;
@Property(name = "title")
private String title;
}
关联关系
@Data
@RelationshipEntity(type = "DOWNSTREAM_OF")
public class DownstreamOfRelationShip {
@Id
@GeneratedValue
private Long id;
@StartNode
private Person startNode;
@EndNode
private Person endNode;
@Property("relation_ship_id")
private String relationShipId;
}
持久层
@Repository
public interface NodeRepository extends Neo4jRepository<Node,Long> {
@Query("MATCH p=(n:Person) RETURN p")
List<Node> selectAll();
@Query("MATCH(p:Person{name:{name}}) return p")
Node findByName(String name);
}
使用
@Slf4j
@Service
public class NodeServiceImpl implements NodeService {
@Autowired
private NodeRepository nodeRepository;
@Override
public Node addNode(Node node) {
Node node = nodeRepository.save(node);
return node ;
}
public Node findNode(String name) {
Node node = nodeRepository.findByName(name);
return node;
}
}
到了这里,关于Neo4j开发的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!