我正在使用Play Framework 2.7.x
我在controller.list()
上有一个方形的视图,我们称其为"索引"。单击"发送"打开的controller.add()
之后,它可以在其中一些东西,然后重定向到controller.list()
。如果在格式中存在错误(所需的字段是空的(,则我需要查询,该QUERYSTRING已发送到controller.add()
,也将其重定向到controller.list()
问题是,如果我做的事情像通过请求,我会发现一个错误,无法添加参数。
public Result list(Http.Request request)
{
// .... stuff with foo, while foo is an Form<foo> Object
// ... foo.bindFromRequest(request)
ok(views.html.index.render(foo))
}
public Result add(Http.Request request)
{
// not allowed to add request as an argument. only empty is allowed.
return Results.redirect(controllers.routes.Controller.list(request));
}
我只想重定向对象,因此我可以处理controller.list()
中的错误,而不必为controller.add()
生成额外的视图。如果我在controller.list()
内完成所有操作,则此代码没有问题,但是我喜欢使用controller.add()
方法。
是一个选项吗?除了手动传递每个querystring key and value
。
我昨天昨天半天搜索后,我发现今天有些东西正在互相。
-
您不允许使用
=
使用默认参数。您必须在routes
内使用可选的默认参数,并使用?=
! -
您可以实现
QueryStringBindable
,因此绑定查询字符串更容易。但是您仍然必须"手动"束缚它们。