Scala Play 2,传递请求到方法
发布时间:2020-12-16 18:57:36 所属栏目:安全 来源:网络整理
导读:我有一个Play 2.0应用程序 TestController.scala def foo(p1: String) = Action {implicit request = Ok(bar(p1))}private def bar(p1: String) = {//access request parameter here} 有没有办法使用implicit来将请求传递给bar 解决方法 是的你可以: def fo
我有一个Play 2.0应用程序
TestController.scala def foo(p1: String) = Action {implicit request => Ok(bar(p1)) } private def bar(p1: String) = { //access request parameter here } 有没有办法使用implicit来将请求传递给bar 解决方法
是的你可以:
def foo(p1: String) = Action { implicit request => Ok(bar(p1)) } private def bar(p1: String)(implicit req: RequestHeader) = "content" 代码: Action { implicit request 在Action对象上调用此方法: def apply(block: Request[AnyContent] => Result): Action[AnyContent] = { 所以,你所谓的“请求”与名为“块”的参数匹配.这里的“implicit”是可选的:它使“请求”值作为其他方法/函数调用的隐式参数可用. 在“bar”函数中隐含的表示它可以从一个隐式值中获取“req”的值,并不一定需要显式传递. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |