Ian*_*cey 2 java spring neo4j spring-data-neo4j spring-boot
我正在尝试使用此查询在计算字段的旁边返回节点对象。从理论上讲,这应该返回一个哈希,我可以访问每个人,然后计数并将其输入速度模板。
MATCH (starter:Person {userId: {0}})<-[r:WORKS_FOR]-(n:Person) OPTIONAL MATCH (n)<-[q:WORKS_FOR]-(p:Person) RETURN {person: n, reporteeCount: count(q)}
我可以在Neo4j浏览器中返回值,但未能成功引用返回类型并在spring-boot中访问Java中的数据。
我们当前的配置是使用PersonRepository访问数据,然后使用PersonService和PersonServiceImpl以便将返回的数据从Neo4j传递到我们的PersonController。
我认为您想要的是一个@QueryResult批注的DTO,以使您的人员+ reporteeCount
@QueryResult
class PersonWithHash {
Person person;
int reporteeCount;
}
// in PersonRepository
@Query("MATCH (starter:Person {userId: {0}})<-[r:WORKS_FOR]-(n:Person) OPTIONAL MATCH (n)<-[q:WORKS_FOR]-(p:Person) RETURN n as person, count(q) as reporteeCount")
Collection<PersonWithHash> findBy...(String userId);
Run Code Online (Sandbox Code Playgroud)
注意查询RETURN子句的更改
| 归档时间: |
|
| 查看次数: |
1160 次 |
| 最近记录: |