How to handle optional query parameters in Play framework

后端 未结 6 1582
礼貌的吻别
礼貌的吻别 2020-12-07 22:28

Lets say I have an already functioning Play 2.0 framework based application in Scala that serves a URL such as:

http://localhost:9000/birthdays

which respond

6条回答
  •  庸人自扰
    2020-12-07 23:12

    Encode your optional parameters as Option[String] (or Option[java.util.Date], but you’ll have to implement your own QueryStringBindable[Date]):

    def birthdays(from: Option[String], to: Option[String]) = Action {
      // …
    }
    

    And declare the following route:

    GET   /birthday       controllers.Application.birthday(from: Option[String], to: Option[String])
    

提交回复
热议问题