[英]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.