查询语句如下:
MATCH data = (a)-[*1..2]->(b) RETURN nodes(data) as nodes, relationships(data) as relationships;
问题总结:
如果直接在Repository中使用@Query查询
1、直接用对象接收报错:Could not find mappable nodes or relationships inside Record<{nodes: [node<58501>, node<15619>], relationships: [relationship<5>]}> for org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity@270d6606
2、用List<Map<String, Object>>接收报错:Records with more than one value cannot be converted without a mapper
如果用Neo4jClient查询
1、用Collection<Map<String,Object>>接收 返回值value为空{}
2、直接用对象接收报错:No converter found capable of converting from type [org.neo4j.driver.internal.value.ListValue] to type [com.kh.graph.domain.PathResult]
下面是我创建的实体
@Data
public class PathResult {
private List<NodesVO> nodes;
private List<RelationshipsVO> relationships;
}
@Data
@Node
public class NodesVO {
@Id
@GeneratedValue
private Long id;
private List<String> labels;
private Map<String, Object> properties;
}
@Data
@RelationshipProperties
public class RelationshipsVO {
@Id
@GeneratedValue
private Long id;
private Long start;
private Long end;
private String type;
private Map<String, Object> properties;
}