2013-04-16 15 views
0

早上好, 我有一個Neo4j數據庫與Maven依賴關係通過Java程序構建。現在我想創建一個Web界面來訪問數據。 當通過jQuery.ajax執行密碼POST時,我得到一個錯誤的請求錯誤。 在細節:參數找不到在密碼查詢中執行通過休息在javascript

var query2 = '{"query":"start n = node(*) where n.groupId! = {groupId} and n.artifactId! = {artifactId} return n.version","params":{"groupId":"junit","artifactId":"junit"}}'; 

當我通過其餘發送此服務器,我得到一個400錯誤請求錯誤:

{ "message" : "Expected a parameter named groupId", "exception" : "BadInputException", "stacktrace" : [ "org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnHasNext(RepresentationExceptionHandlingIterable.java:51)", "org.neo4j.helpers.collection.ExceptionHandlingIterable$1.hasNext(ExceptionHandlingIterable.java:61)", "org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)", "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:58)", "org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)", "org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)", "org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:50)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:42)", "org.neo4j.server.rest.repr.OutputFormat.format(OutputFormat.java:170)", "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:120)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:107)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:55)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:68)", "java.lang.reflect.Method.invoke(Unknown Source)" ] }

我也試着通過JS對象來構建查詢,像這樣:

 var query = {}; 
    query["query"] = text; 
    query["params"] = JSON.parse("{" + params + "}"); 

其中text是查詢字符串,並用正確的語法參數參數。 (「param1」:「value1」,...)

直到現在,這似乎是我錯誤地輸入了某些東西。 有趣的是,當省略參數並僅使用「查詢」屬性編寫請求時,整個工作就會起作用。

而且

JSONObject jObject = new JSONObject(); 
     Map<String, Object> params = new HashMap<String, Object>(); 
     params.put("groupId", "junit"); 
     params.put("artifactId", "junit"); 
     String query = "start n = node(*) where n.groupId! = {groupId} and n.artifactId! = {artifactId} return n.version"; 
     jObject.put("query", query); 
     jObject.put("params", params); 

,然後在Java中發送jObject.toString()到數據庫就像一個魅力... 好吧,我不得不說我在我的機智與這個目的。 希望你們能幫助我:)

回答

1

您是否提供content-type:application/jsonaccept:application/json請求標題?

+0

嗯,我不認爲這會是一個問題。以爲我讀了json是默認的地方... 無論如何,它現在可以與dataType:json和contentType:application/json一起使用,當我提供字符串化對象時。 接受沒有改變任何東西:/ 奇怪的是沒有參數的查詢不需要規範... –

相關問題