Kev*_*ith 3 redirect scala playframework
当我正在实施 TinyUrl 时,我想根据输入哈希将用户重定向到网页。
def getTask(hash: Int) = Action {
val url: Option[String] = Task.getTask(hash)
// redirect to show(url)
}
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何将用户重定向到外部 URL。
我看到了这个相关的帖子,但是我在使用时遇到了这个编译时错误redirect
not found: value redirect
redirect不存在。
但是Redirect,它是play.api.mvc包的成员,确实如此。
以下是您的操作应该是什么样子的示例:
import play.api.mvc._
def getTask(hash: Int) = Action {
val url: Option[String] = Task.getTask(hash)
url match {
case Some(url) => Redirect(url)
case None => NotFound("This URL leads nowhere. :(")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1835 次 |
| 最近记录: |