1
我想送我的模型的對象作爲參數上PlayFramework
的這個PathBindable有什麼問題?
一個GET
我創建的case class Game
,看起來是這樣的:
case class Game(name: String, url: String){
}
,當我試圖將其發送作爲參數傳遞給我的方法是這樣的(routes文件):
GET /trophies/:game controllers.Application.trophies(game: model.Game)
它告訴我,我需要一個PathBindable
對象,所以我做了一些研究,並與實施來到餘噸hought是有效的:
case class Game(name: String, url: String) implements PathBindable[Game] {
def bind(key: String, value: String): Game = {
val text = value.split(";")
Game(text(0), text(1))
}
def unbind(key: String, game: Game): String = {
game.name + ";" + game.url
}
def javascriptUnbind(): String = ???
def unbind(x$1: String): String = ???
}
要綁定它,我從與;
分割字符串創建Game
和取消綁定,我只是創建劃分的字符串。
當我使用它時,我得到一個Bad Request
,聲明找不到Action,但它存在,就像我在上面的路由文件片段中顯示的那樣。
我的實施有什麼問題嗎?
'bind'應該返回一個'Either'?嘗試在「def」之前添加'override'。 – david
檢查API ..應返回'Either' http://www.playframework.com/documentation/2.1.0/api/scala/index.html#play.api.mvc.PathBindable – Shrey
奇怪的是,你得到錯誤的請求(響應代碼400),而不是找不到400。你能給我們一個例子(即遊戲和URL)嗎? – Schleichardt