简体   繁体   中英

Spring-data-neo4j get nodes and labels

I am currently usring Spring and neo4j . One mission is to display the graph using linkurious . However, how can I tell Spring through spring-data-neo4j the labels of the nodes? I need the labels to color the graph in linkurious. If using findAll() defined in the graph repository, only node properties will be returned?

Any suggestion?

UPDATE

I tried to use @QueryResult , but there's something wrong with the respond. 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 [{},{},{},{}] . 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.

SDN 4.0 does not map nodes/relations to domain entities in a @QueryResult. The code you've posted will work with SDN 4.1

If you want to achieve the same in SDN 4.0, you can do this:

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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