3

我改变了一个功能:

def submit = Action { request =>
  signupForm.bindFromRequest()(request).fold(
    // Form has errors
    errors => BadRequest(html.signup.form(errors)),

    // We got a valid User value, display the summary
    user => {
      // intensive computation involving database
      Ok("okay")
    }
  )
}

def submit = Action { request =>
  val result = Akka.future {
    signupForm.bindFromRequest()(request).fold(
      // Form has errors
      errors => BadRequest(html.signup.form(errors)),

      // We got a valid User value, display the summary
      user => {
        // intensive computation involving database
        Ok("okay")
      }
    )
  }
  Async {
    result
  }
}

我得到以下编译错误:

[error]  found   : play.api.mvc.SimpleResult[_ >: java.lang.String with play.api.templates.Html <: java.io.Serializable]
[error]  required: play.api.mvc.SimpleResult[_1(in value result)] where type _1(in value result) >: java.lang.String with play.api.templates.Html <: java.io.Serializable
[error] Note: java.io.Serializable >: _1, but class SimpleResult is invariant in type A.
[error] You may wish to define A as -A instead. (SLS 4.5)
[error]       signupForm.bindFromRequest()(request).fold(
[error]                                                 ^
[error] one error found

错误消息似乎与方差有关。有谁明白发生了什么?

4

1 回答 1

1

BadRequest正在返回类型SimpleResult[Html]
Ok正在返回类型SimpleResult[String]

如果您制作BadRequestOk返回相同的类型,那么它将起作用。

尝试做Ok(Html("ok"))- 或实际呈现页面。

于 2012-10-22T01:12:16.267 回答