Play框架 - Scala,Method定义了两次

Far*_*hin 5 scala playframework playframework-2.0 playframework-2.1

我想将多个URL映射到重载的控制器方法,如下所示.但我收到错误"方法帐户定义了两次".那么,是否可以在scala-play框架中执行此操作?

GET     /order/:userId             controllers.Application.account(userId)       
GET     /order/:userId/:date       controllers.Application.account(userId, date)
Run Code Online (Sandbox Code Playgroud)

And*_*ner 10

由于反向路由的工作方式,您需要指定要使用的两个参数account.这是一个有效的例子:

在Application.scala中:

def account(userId: String, date: String) = Action {
  Ok(userId + " and " + date)
}
Run Code Online (Sandbox Code Playgroud)

在路线:

GET /order/:userId           controllers.Application.account(userId, date="")
GET /order/:userId/:date     controllers.Application.account(userId, date)
Run Code Online (Sandbox Code Playgroud)