如何访问neo4j非托管扩展的节点属性

时间:2015-08-11 14:27:34

标签: java neo4j

我是neo4j和非托管扩展的新手。

我只是在neo4j中编写HelloWorld示例,代码如下

//START SNIPPET: HelloWorldResource
@Path( "/helloworld" )
public class HelloWorldResource
{
    private final GraphDatabaseService database;

    public HelloWorldResource( @Context GraphDatabaseService database )
    {
        this.database = database;
    }

    @GET
    @Produces( MediaType.TEXT_PLAIN )
    @Path( "/{nodeId}" )
    public Response hello( @PathParam( "nodeId" ) long nodeId )
    {  
        // Do stuff with the database

        return Response.status( Status.OK ).entity(
                ("Hello World2, nodeId=" + nodeId + ", ADDRESSNO = " +     "").getBytes( Charset.forName("UTF-8") ) ).build();
    }
}

如何访问节点,其id为nodeId

如何访问其地址属性

1 个答案:

答案 0 :(得分:1)

hello方法中:

try (Transaction tx = database.beginTx()) {
    Node n = database.getNodeById(nodeId);
    String address = (String)n.getProperty("address", null);

    tx.success();
}