我正在尝试使用Neo4j Java Bolt驱动程序创建一个具有许多属性的节点。我的代码目前看起来像这样:
String statement =
" CREATE (p:Person {id: {id}, firstName: {firstName}, lastName: {lastName}, gender: {gender}, birthday: {birthday}, creationDate: {creationDate}, locationIp: {locationIp}, browserUsed: {browserUsed}, speaks: {speaks}, emails: {emails}})";
String parameters = parameters(
"id", String.valueOf(operation.personId()),
"firstName", operation.personFirstName(),
"lastName", operation.personLastName(),
"gender", operation.gender(),
"birthday", operation.birthday().getTime(),
"creationDate", operation.creationDate().getTime(),
"locationIP", operation.locationIp(),
"browserUsed", operation.browserUsed(),
"speaks", operation.languages(),
"emails", operation.emails());
try (Session session = driver.session(AccessMode.WRITE)) {
try (Transaction tx = session.beginTransaction()) {
StatementResult result = tx.run(statement, params);
tx.success();
tx.close();
}
}
但是使用HTTP和JSON,可以将语句简化为:
String statement =
" CREATE (p:Person {props})";
并发送一个类似于:
的JSON对象{props:
{id: bla,
firstName: bla,
lastName: bla,
...
}
}
Neo4j Bolt驱动程序API中是否有一种方法可以使用后一版本的CREATE
语句并将参数作为地图提供?
答案 0 :(得分:0)
这与API无关。不推荐CREATE (p:Person {props})
语法支持:
CREATE (p:Person) SET p = {props}
或者如果你想要添加
CREATE (p:Person) SET p += {props}
您也可以一次设置多个。
使用螺栓驱动程序,您发送了一张地图。或Values.parameters("id", id, "firstName", firstname, ...)