[英]Neo4j Java Bolt Driver: Creating node with many properties
我正在尝试使用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
语句的后一版本并提供参数作为映射?
这独立于API。 不建议使用CREATE (p:Person {props})
语法,而推荐使用:
CREATE (p:Person) SET p = {props}
或者如果您想添加
CREATE (p:Person) SET p += {props}
您也可以一次设置多个。
参见: https : //neo4j.com/docs/developer-manual/current/cypher/clauses/create/#create-create-node-with-a-parameter-for-the-properties
使用螺栓驱动程序,您可以发送地图。 或Values.parameters("id", id, "firstName", firstname, ...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.