How to handle optional query parameters in Play framework

后端 未结 6 1588
礼貌的吻别
礼貌的吻别 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:08

    For optional Query parameters, you can do it this way

    In routes file, declare API

    GET   /birthdays     controllers.Application.method(from: Long, to: Long)
    

    You can also give some default value, in case API doesn't contain these query params it will automatically assign the default values to these params

    GET   /birthdays    controllers.Application.method(from: Long ?= 0, to: Long ?= 10)
    

    In method written inside controller Application these params will have value null if no default values assigned else default values.

提交回复
热议问题