Play framework - Scala, the method is defined twice

I want to map multiple URLs in overloaded controller mode, as shown below. But I get the error "The method account is defined twice." So, is it possible to do this in scala - play framework?

GET     /order/:userId             controllers.Application.account(userId)       
GET     /order/:userId/:date       controllers.Application.account(userId, date)
+5
source share
1 answer

Due to how reverse routing works, you need to specify both parameters to use account. Here is an example that works:

In Application.scala:

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

In routes:

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

All Articles