我在 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/