Scala playframework中的composeAction:取一个参数,返回相同的值,为什么需要它?
函数使用一个动作,返回相同的动作,它的目的是什么,它既没有副作用也没有任何转换。在我看来,它并不是什么都没有,比如var a=a,它有什么用处Scala playframework中的composeAction:取一个参数,返回相同的值,为什么需要它?,scala,playframework,Scala,Playframework,函数使用一个动作,返回相同的动作,它的目的是什么,它既没有副作用也没有任何转换。在我看来,它并不是什么都没有,比如var a=a,它有什么用处 protected def composeAction[A](action: Action[A]): Action[A] = action 正如你所说,它本身什么都不做。它的意思是作为一个占位符,在编写Actions时被覆盖,如中所述: 我们现在为Scala应用程序提供了一个ActionBuilder特性 允许更强大的动作堆栈构建。例如: 正如你所说,
protected def composeAction[A](action: Action[A]): Action[A] = action
正如你所说,它本身什么都不做。它的意思是作为一个占位符,在编写
Action
s时被覆盖,如中所述:
我们现在为Scala应用程序提供了一个ActionBuilder特性
允许更强大的动作堆栈构建。例如:
正如你所说,它本身什么都不做。它的意思是作为一个占位符,在编写
Action
s时被覆盖,如中所述:
我们现在为Scala应用程序提供了一个ActionBuilder特性
允许更强大的动作堆栈构建。例如:
object MyAction extends ActionBuilder[AuthenticatedRequest] {
def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[SimpleResult]) = {
// Authenticate the action and wrap the request in an authenticated request
getUserFromRequest(request).map { user =>
block(new AuthenticatedRequest(user, request))
} getOrElse Future.successful(Forbidden)
}
// Compose the action with a logging action, a CSRF checking action, and an action that only allows HTTPS
def composeAction[A](action: Action[A]) =
LoggingAction(CheckCSRF(OnlyHttpsAction(action)))
}