我想将多个 URL 映射到一个重载的 Controller 方法中,如下所示。但是我收到错误“方法帐户定义了两次”。那么,是否可以在 Scala-play 框架中做到这一点?
GET /order/:userId controllers.Application.account(userId)
GET /order/:userId/:date controllers.Application.account(userId, date)
最佳答案
由于反向路由的工作方式,您需要指定两个参数才能使用 account
像那样。这是一个有效的例子:
在 Application.scala 中:
def account(userId: String, date: String) = Action {
Ok(userId + " and " + date)
}
在 route :
GET /order/:userId controllers.Application.account(userId, date="")
GET /order/:userId/:date controllers.Application.account(userId, date)
关于scala - Play 框架 - Scala,方法被定义两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12516436/