0

我们正在从 Grails 2.x 迁移到 3.x。使用 forward 函数时,我可以观察到一些不同的行为:

class FooController {

    def index() {
        forward controller: 'foo', action : 'bar', params: params
    }

    def bar() {
        render(
                view: "/foo/foo"
        )
    }
}

当调用http://localhost:8080/foo?test=1并在方法中停止时,bar()我可以看到params如下所示:

params = {GrailsParameterMap@11597}  size = 4
 0 = {LinkedHashMap$Entry@11607} "test" -> 
  key = "test"
  value = {String[2]@11612} 
   0 = "1"
   1 = "1"
 1 = {LinkedHashMap$Entry@11608} "controller" -> "foo"
 2 = {LinkedHashMap$Entry@11609} "format" -> "null"
 3 = {LinkedHashMap$Entry@11610} "action" -> "bar"

如您所见, 的值test被保存为String[]. 这种行为与 Grails 2.5.6 中的行为不同。有没有办法为 Grailsforward函数设置一个标志,以便不将参数传递给重定向控制器?

4

1 回答 1

1

我认为您不需要添加param. forward自动转发您的参数。这是可选的。如果添加它,它将复制这些值。仅尝试:

forward controller: 'foo', action : 'bar'
于 2019-02-10T19:57:42.950 回答