play.api.mvc中的对象Action在哪里? [英] Where is the object Action in play.api.mvc?

查看:78
本文介绍了play.api.mvc中的对象Action在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am a novice of Play Framework. When I learn it on its webpages. I found some code like this:

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

我检查了它的文档,并且ActionBuilder中有一个功能async.

I checked its document and there is a function async in ActionBuilder.

Action.async如何工作?似乎在play.api.mvc

推荐答案

object Action在Play 2.8中已被删除不推荐使用的play.api.mvc.Action#9288 ,并已由注入的方法 controllerComponents.actionBuilder而不是全局对象

object Action has been removed in Play 2.8 by Remove deprecated play.api.mvc.Action #9288, and has been replaced by BaseController.Action method which refers to injected controllerComponents.actionBuilder rather than the global objects

  /**
   * ...
   * 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

注意方法名称如何以大写字母开头(也许是非常规的).我的假设是这样做是为了保持熟悉的用法

Notice how, perhaps unconventionally, the method name begins with an uppercase letter. My assumption is this was done to maintain familiar usage

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

这篇关于play.api.mvc中的对象Action在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆