播放框架-使用参数重定向 [英] Play Framework - Redirect with params

查看:84
本文介绍了播放框架-使用参数重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何使用Scala在Play(2.0)中的控制器动作中进行重定向.

I am trying to figure out how to do a redirect within a controller action in Play (2.0) using Scala.

使用重定向

Redirect(routes.Application.index)

工作正常.

我无法从文档,API或Google中弄清楚的是如何向调用中添加参数.

What I cannot figure out from the docs, API, or Google is how to add parameters to the call.

我来自Grails,可以很容易地做到以下几点:

I am coming from Grails where this could be done easily as follows:

重定向操作:索引",参数:[键":值"]

redirect action: "index", params: ["key": "value"] .

我发现的唯一方法是使用字符串url和查询字符串调用重定向,这似乎很尴尬.

The only way I have found is to call Redirect using a string url and a query string, which seems awkward.

基本上,我想以某种方式使用Redirect(Call),但我不打算使用反向路由来创建Call对象.

Basically I would like to make use of Redirect(Call) somehow, but I do not how to create the Call object using reverse routing.

我是否错过了某些东西/没有在Play/Scala中理解这个概念?

Am I missing something/not getting the concept in Play/Scala?

预先感谢!

推荐答案

Ellou'

路由只是一个函数,因此您可以照常传递参数:

A route is just a function, so you can pass arguments as usual:

// Redirect to /hello/Bob
def helloBob = Action {
    Redirect(routes.Application.hello("Bob"))    
}

此代码段来自 http://www.playframework.org/documentation/2.0/ScalaRouting (在底部)

This snippet comes from http://www.playframework.org/documentation/2.0/ScalaRouting (at the bottom)

这篇关于播放框架-使用参数重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆