【问题标题】:Grails 3.3.9: Forward copies paramsGrails 3.3.9:转发复制参数
【发布时间】:2019-02-08 14:30:49
【问题描述】:

我们正在从 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 中的行为不同。 有什么方法可以为 Grails forward 函数设置一个标志,以免将参数传递给重定向控制器?

【问题讨论】:

    标签: grails grails-controller grails3 grails-3.3 grails-3.3.x


    【解决方案1】:

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

    forward controller: 'foo', action : 'bar'
    

    【讨论】:

    • 是的,我也是这么怀疑的。但是最好有一些关于 forward 函数的文档,看看它是否支持某种选项参数......但没有。
    • 不幸的是,没有明确的文档,但您可以查看最新的实现或在本地调试以查看发生了什么:github.com/grails/grails-core/blob/master/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多