Scala - 不能使用返回 play.api.mvc.Result 作为请求处理程序的方法

标签 scala playframework playframework-2.0

我在 Scala 中有这个 Controller :

def commonRedirect(anId: Long) = {
implicit val aRule = CommonClient.getTheRule(anId)
aRule match {
  case false ⇒ Redirect("/general-rule/" + anId)
  case true  ⇒ Redirect("/custom-rule/" + anId)
}

}

但是,这会导致错误:“无法使用返回 play.api.mvc.Result 作为请求处理程序的方法”。

如果我应用 Action Builder,它会起作用,但这不是我想要的方式。

任何想法来解决这个问题?

谢谢。

最佳答案

您需要制作一个 Action .

def commonRedirect(anId: Long) = Action {
  implicit val aRule = CommonClient.getTheRule(anId)
  aRule match {
    case false ⇒ Redirect("/general-rule/" + anId)
    case true  ⇒ Redirect("/custom-rule/" + anId)
  }
}

关于Scala - 不能使用返回 play.api.mvc.Result 作为请求处理程序的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35483108/

相关文章:

scala - 比较 RDD 的子集

scala - Scala 对象(非类)的单元测试

regex - 如何从 Scala 中的文本中删除数字?

scala - 具有外部数据库和 RESTful Web gui 和服务的系统的正确设计是什么?

Scala/Play/Akka : delay action response

java - 玩! Java 8 的框架支持 可选

Scala Slick : MappedColumnType cannot find implicit value for BaseColumlnType[String]

playframework - 如何在 Play Framework 中定义任意任务? (如 ruby rake )

java - Play 框架和 Office 365 OAuth

playframework - Ebean如何排除字符串作为列