Play Framework 2,为什么操作和请求采用类型参数?

时间:2015-07-16 13:01:51

标签: scala playframework type-parameter

为什么Play Framework中的操作和请求会采用类似参数,如下面的代码所示?

import play.api.mvc._

case class Logging[A](action: Action[A]) extends Action[A] {

  def apply(request: Request[A]): Future[SimpleResult] = {
    Logger.info("Calling action")
    action(request)
  }

  lazy val parser = action.parser
}

1 个答案:

答案 0 :(得分:1)

如果您查看操作文档here

此类型

type BODY_CONTENT = A

Type of the request body.

如果您知道,可以申请

text/plain: String
application/json: JsValue
text/xml: NodeSeq
application/form-url-encoded: Map[String, Seq[String]]
multipart/form-data: MultipartFormData[TemporaryFile]
any other content type: RawBuffer

还可以看一下:身体解析器

https://www.playframework.com/documentation/2.0/ScalaBodyParsers