首页 > 解决方案 > 从 Neo4j 接收 JSON 数据到 Spring Boot API

问题描述

我正在尝试将数据从 Neo4J 发送到 Spring boot,并且我想收到这样的 JSON:

{
  "name": "Alex Statham",
  "people": [
    {
      "name": "Jason Statham",
      "people": [
        {
          "name": "Lyna Statham"
        },
        {
          "name": "John Statham"
        }
      ]
    },
    {
      "name": "Will Statham",
      "people": [
        {
          "name": "Michael Statham"
        }
      ]
    }
  ]
}

我尝试了很多查询,这可能是最好的查询,它为所有情况返回正确的家谱,但它只返回没有关系的节点,所以我不能把这些数据放到我使用的库中:

MATCH (p1:Person {maBN:3})
CALL apoc.path.subgraphNodes(p1, {
    sequence: '>Person,FCHILD,>Person,FCHILD,>Person',
    maxLevel: 6
}) YIELD node
RETURN node, p1

这是那个库:https ://www.npmjs.com/package/react-tree-graph

我应该怎么办?我对 Cypher 和 Neo4j 不太了解。

标签: springapineo4jcypher

解决方案


您可以使用 apoc.convert.toTree 获取路径列表并创建像您这样的结构。


推荐阅读