【问题标题】:Play Framework 2.5 Error with Simple Controller使用简单控制器播放框架 2.5 错误
【发布时间】:2016-06-17 05:09:59
【问题描述】:

在尝试使用简单控制器的 Play framework 2.5 时收到的错误消息令人费解。这是我正在做的事情:

object UserController extends Controller {

  def login = Action.async(BodyParsers.parse.json) { request =>
    val body = request.body.validate[UserLogin]
    // call the userService and validate the credentials
    body.fold(
      errors => {
        BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors)))
      }, // error here
      message => {
        Ok("")
      } // error here
    )
  }
}

我收到错误消息:

"Expression of type Result does not conform to expected type _X"

【问题讨论】:

  • 我认为您可以删除“异步”调用或将两个响应包装在“Future.successful”中

标签: scala playframework


【解决方案1】:

我需要将调用包装在 Future 中!所以这里是如何做到的!

object UserController extends Controller {

  def login = Action.async(BodyParsers.parse.json) { request =>
    val body = request.body.validate[UserLogin]
    // call the userService and validate the credentials
    body.fold(
      errors => {
        Future.successful { BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors))) }
      }, // error here
      message => {
        Future.successful { Ok("") }
      } // error here
    )
  }
}

【讨论】:

  • 你能暴露怎么做吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多