【发布时间】:2019-06-07 09:18:51
【问题描述】:
对于我的一条路线,我有一个可选参数,即birthDate: Option[String],并且可以这样做:
GET /rest/api/findSomeone/:firstName/:lastName controllers.PeopleController.findSomeone(firstName: String, lastName: String, birthDate: Option[String])
但是,为了更严格地使用 birthDate 可选参数,指定这样的正则表达式会很有帮助:
$birthDate<([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))>
但由于这是一个可选参数,我找不到这样做的方法.. 这在 Play 2.7.x 中有所涵盖吗?我面临着将birthDate 参数设为非可选或不选中它的两难境地。
作为旁注。我一直在尝试整合 Joda time 的路由绑定,例如org.joda.time.LocalDate 通过添加以下依赖项 https://github.com/tototoshi/play-joda-routes-binder "com.github.tototoshi" %% "play-joda-routes-binder" % "1.3.0" 但它在我的项目中不起作用,因为我在集成后遇到编译错误,所以我暂时隐藏了这种方法。
【问题讨论】:
-
在读取值时进行正则表达式验证,而不是在路由上
-
所以答案是在 2.7.x 或 2.7.x 中不可能使用正则表达式在路由中验证可选参数?
-
我不知道这是否可能(编程中一切皆有可能),但这绝对不是最好的方法
标签: scala playframework play-framework-2.7