0

在超类中,我定义了一个函数:

def render(model: JsonModel) {
    if (!model.isOk()) {
      BadRequest(model.toJsonString()).withHeaders("Content-Type" -> "application/json; charset=utf-8")
    } else {
      Ok(model.toJsonString()).withHeaders("Content-Type" -> "application/json; charset=utf-8")
    }
  }

我想在我的子类中调用这个函数:

def test(model: JsonModel) = Action { implicit request =>
  render(model)  
}

这不起作用并抱怨 - 类型不匹配;找到:需要单位

如果我摆脱隐含的请求

def test(model: JsonModel) = Action { 
  render(model)  
}

它似乎有效,但我有时需要访问请求

4

1 回答 1

4

你的问题在这里:

def render(model: JsonModel) {

render方法返回Unit。我知道无需查看任何其他行,因为它缺少等号。如果你这样写:

def render(model: JsonModel) = {

然后它会返回其他东西,我期望这是需要的。

于 2011-12-22T01:29:02.420 回答