5

複数のURLを以下のようにオーバーロードされたコントローラメソッドにマップしたいと思います。しかし、私はエラー "メソッドアカウントは2回定義されて"取得します。それで、スカラープレイフレームワークでこれを行うことは可能でしょうか?Play framework - Scala、メソッドが2回定義されています

GET  /order/:userId    controllers.Application.account(userId)  
GET  /order/:userId/:date  controllers.Application.account(userId, date) 

答えて

10

逆ルーティングが機能するため、両方のパラメータを指定して、accountのようにする必要があります。 Application.scalaで

def account(userId: String, date: String) = Action { 
    Ok(userId + " and " + date) 
} 

をルートに:ここで働く例です

GET /order/:userId   controllers.Application.account(userId, date="") 
GET /order/:userId/:date  controllers.Application.account(userId, date) 
+1

+1それでも、チャンクの吹き込み、無オーバーロード;-( – virtualeyes

関連する問題