我是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
如何访问其地址属性
答案 0 :(得分:1)
在hello
方法中:
try (Transaction tx = database.beginTx()) {
Node n = database.getNodeById(nodeId);
String address = (String)n.getProperty("address", null);
tx.success();
}