Play 2 中的 Scala Action 方法
Scala Action method in Play 2
我是 Scala 的新手,我也在学习 Play。我看到 Play
中使用了以下结构
def list = Action {
val products = Product.findAll
Ok(views.html.products.list(products))
}
我很困惑
Action {}
确实如此。 Action
是方法的返回值吗?如果我想了解更多,这个结构叫什么?
这个构造叫做factory method enhanced via scala apply sugar
Action
在这个引用中是 companion object, which could be called singleton,但实际上随着非常具体的单例类型 Action$
它的方法反映为 Action
的静态方法。
我们可以阅读 object Action extends ActionBuilder[Request]
which have plenty of apply methods 构建 Action
类型的值。
这里的大括号表示 nullary function which is null-parameter closure,并且经常以不同的语言命名,例如 ruby 或 groovy。它只是多行代码块,最后会产生一些东西。
我是 Scala 的新手,我也在学习 Play。我看到 Play
中使用了以下结构def list = Action {
val products = Product.findAll
Ok(views.html.products.list(products))
}
我很困惑
Action {}
确实如此。 Action
是方法的返回值吗?如果我想了解更多,这个结构叫什么?
这个构造叫做factory method enhanced via scala apply sugar
Action
在这个引用中是 companion object, which could be called singleton,但实际上随着非常具体的单例类型 Action$
它的方法反映为 Action
的静态方法。
我们可以阅读 object Action extends ActionBuilder[Request]
which have plenty of apply methods 构建 Action
类型的值。
这里的大括号表示 nullary function which is null-parameter closure,并且经常以不同的语言命名,例如 ruby 或 groovy。它只是多行代码块,最后会产生一些东西。