我开始将 Neo4J 与 Spring Data Rest 一起使用。我有一个节点实体和一个关系实体,用于建模节点和边。我可以使用邮递员使用以下内容创建新节点。
POST http://localhost:8080/nodes
{
"name" : "Test"
}
我不确定在节点之间创建关系的 JSON 格式是什么。例如:
- 创建一个新节点并与现有节点相关联
- 在两个现有节点之间创建关系。
非常感谢任何关于我需要使用什么 JSON 的示例。
我的节点实体和关系实体如下:
@NodeEntity
public class Node {
@Id
@GeneratedValue
private Long id;
private String name;
private int count;
@Relationship(type = Edge.TYPE, direction = Relationship.UNDIRECTED)
private Set<Edge> edges = new HashSet<>();
public void addEdge(Node target, int count) {
this.edges.add(new Edge(this, target, count));
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Set<Edge> getEdges() {
return edges;
}
public void setEdges(Set<Edge> edges) {
this.edges = edges;
}
}
@RelationshipEntity(type = Edge.TYPE)
public class Edge {
public static final String TYPE = "LINKED_TO";
@Id
@GeneratedValue
private Long relationshipId;
@StartNode
private Node start;
@EndNode
private Node end;
private int count;
public Edge() {
super();
}
public Edge(Node start, Node end, int count) {
this.start = start;
this.end = end;
this.count = count;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Node getStart() {
return start;
}
public void setStart(Node start) {
this.start = start;
}
public Node getEnd() {
return end;
}
public void setEnd(Node end) {
this.end = end;
}
public Long getRelationshipId() {
return relationshipId;
}
public void setRelationshipId(Long relationshipId) {
this.relationshipId = relationshipId;
}
}