我想将多个URL映射到重载的控制器方法,如下所示。但我收到错误“方法帐户定义了两次”。那么,是否可以在scala-play框架中执行此操作?
GET /order/:userId controllers.Application.account(userId)
GET /order/:userId/:date controllers.Application.account(userId, date)
答案 0 :(得分: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)