我是scala框架的新手。我正在尝试根据输入的url返回虚拟数据。请参考以下场景:
GET /test ---> return fist test passed
GET /test/10 ---> return with param test passed
GET /test?id=10 ---> return with query param test passed
other wise ---> return no test passed在路由中,我定义如下:
GET /test/:key com.test.controller.TestController.index(key: Option[String])控制器:
def index[A](key: Option[String]) = Action {implicit request =>
val test= key match {
case Some(type :String)=>
Ok("first test")
case None =>
Ok("No test found")
}
}在控制器中,我不确定如何检查所有场景。在这方面请帮帮我
发布于 2019-01-23 19:39:35
使用Play 2.0更高版本..
路由文件
GET /test/:key com.test.controller.TestController.index(key: Option[String])控制器:
def index(key: Option[String]) = Action { implicit request =>
key match {
case Some(type :String)=> Ok("first test")
case _ => Ok("No test found")
}
}也许这会解决你的问题..
https://stackoverflow.com/questions/37248230
复制相似问题