简体   繁体   English

Spring-data-neo4j获取节点和标签

[英]Spring-data-neo4j get nodes and labels

I am currently usring Spring and neo4j . 我目前正在使用Springneo4j One mission is to display the graph using linkurious . 一个任务是使用linkurious显示图。 However, how can I tell Spring through spring-data-neo4j the labels of the nodes? 但是,如何通过spring-data-neo4j告诉Spring节点的标签? I need the labels to color the graph in linkurious. 我需要标签来为图加色。 If using findAll() defined in the graph repository, only node properties will be returned? 如果使用在图形存储库中定义的findAll() ,将仅返回节点属性?

Any suggestion? 有什么建议吗?

UPDATE 更新

I tried to use @QueryResult , but there's something wrong with the respond. 我尝试使用@QueryResult ,但是响应出了点问题。 To be more specific: 更加具体:

I define 我定义

@QueryResult
public class NodeWithLabel {
    GLNode glNode;
    ArrayList<String> labels;
}

then in the repository, I have 然后在存储库中,我有

@Query("MATCH (n:GLNode) RETURN n AS glNode, labels(n) as labels")
Collection<NodeWithLabel> getAllNodesWithLabel();

Finally, I will get a result with ArrayList<E> , so the spring mvc will respond empty like [{},{},{},{}] . 最后,我将得到ArrayList<E>的结果,因此spring mvc将像[{},{},{},{}]一样响应为空。 Normally, such as the embedded findAll() function, a LinkedHashSet<E> should be returned, in this case, the spring mvc can send back a json respond. 通常,例如嵌入式的findAll()函数,应返回LinkedHashSet<E> ,在这种情况下,spring mvc可以发送回json响应。

SDN 4.0 does not map nodes/relations to domain entities in a @QueryResult. SDN 4.0不会将节点/关系映射到@QueryResult中的域实体。 The code you've posted will work with SDN 4.1 您发布的代码将适用于SDN 4.1

If you want to achieve the same in SDN 4.0, you can do this: 如果要在SDN 4.0中实现相同的目的,可以执行以下操作:

@QueryResult
public class NodeWithLabel {
    Long id;
    Map<String,Object> node;
    ArrayList<String> labels;
}


@Query("MATCH (n:GLNode) RETURN ID(n) as id, labels(n) as labels, {properties : n} as node")
Collection<NodeWithLabel> getAllNodesWithLabel();

Note: Strongly recommend that you plan to upgrade to SDN 4.1 注意: 强烈建议您计划升级到SDN 4.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM