scala - 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)
}
我查了它的文档,里面有一个功能async
。ActionBuilder
效果如何Action.async
?好像没有Action
对象play.api.mvc
解决方案
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
}
推荐阅读
- saml - 无论如何,我们可以控制 NotOnOrAfter 属性中定义的 SAML 断言生命周期吗?
- oracle-apex - 强制隐藏和显示区域保持打开状态。从 > 切换到 v
- java - JUnit 测试在 MongoDB 中获取 ObjectID
- python - 如何拆分字符串并将其分配给python中的新列
- c# - 如何返回任务?
- python - 使用烧瓶/python重定向到外部链接的问题
- sql - 当我从我的 sql 到我的 spring-boot 应用程序时,为什么我的 LocalDateTime 变量改变了 5 小时?
- ios - 使 AVMutableComposition 与图像(方面填充)和视频在方面适合
- react-native - 无法在 Animated.View 上使用 onPress() 事件设置为 Position: Absolute - React Native
- oracle - 如果金额字段在记录之间从 + 10 或 -10 变化,则查找重复记录并显示为一条记录