首页 > 解决方案 > play.api.mvc中的对象Action在哪里?

问题描述

我是 Play 框架的新手。当我在它的网页上学习它时。我发现了一些这样的代码:

import play.api.mvc._
def logging[A](action: Action[A]) = Action.async(action.parser) { request =>
  logger.info("Calling action")
  action(request)
}

我查了它的文档,里面有一个功能asyncActionBuilder

效果如何Action.async?好像没有Action对象play.api.mvc

标签: scalaplayframework

解决方案


object Action已在 Play 2.8 中由Remove deprecated play.api.mvc.Action #9288 删除,并已被BaseController.Action引用注入 controllerComponents.actionBuilder而不是全局对象的方法替换

  /**
   * ...
   * This is meant to be a replacement for the now-deprecated Action object, and can be used in the same way.
   */
  def Action: ActionBuilder[Request, AnyContent] = controllerComponents.actionBuilder

请注意,方法名称可能是如何以大写字母开头的。我的假设是这样做是为了保持熟悉的用法

def foo(query: String) = Action {
  Ok
}

推荐阅读