我正在使用playframework 2.3.8並擁有視圖類。在那裏是按鈕:爲什麼我將地圖的類型不匹配作爲路由參數?
<button class="btn btn-default" type="button" onclick="@routes.Application.sendMap(myMap)" method="POST">Send</button>
我想追加一個問題/答案對的地圖在我的控制器類(Application.java):
public static Result sendMap(Map<Question, List<Answer>> sendMap){
Question question4 = new Question("ertw", "SendMap Question?", 34, "Tim");
Answer answer41 = new Answer("werw", "ertw", "SendMap Answer 1!", 12, "Oliver");
Answer answer42 = new Answer("tzsdfu", "ertw", "SendMap Answer 2!", 1, "Marcus");
List<Answer> answerList4 = new ArrayList<Answer>();
answerList4.add(answer41);
answerList4.add(answer42);
sendMap.put(question4, answerList4);
return ok(views.html.frageAntwort.render(sendMap));
}
在我routes.conf我已經加入該控制器類的路線,並使用Map
作爲參數:
POST /QuestionMap controllers.Application.sendMap(Map)
但現在我得到的錯誤:
type mismatch; found : String required: java.util.Map[model.Question,java.util.List[model.Answer]]
爲什麼地圖會被轉換成字符串?
這不是有效的路由配置。我不確定您希望通過網址發送「地圖」問題列表>嗎? –
默認參數type是String:「對於String類型的參數,參數類型是可選的。」 https://www.playframework.com/documentation/2.1.x/JavaRouting –
@ m-z:因此,routing.conf中的參數僅用於生成鏈接的結構而不用於傳輸對象?如果我刪除錯誤的參數'POST \t/QuestionMap \t \t \t controllers.Application.sendMap()'我得到一個沒有足夠參數的錯誤:'方法sendMap沒有足夠的參數:(x $ 1:java.util.Map [ model.Question,java.util.List的[model.Answer]])play.mvc.Result。 未指定的值參數x $ 1.' – hamena314