我们从Grails的2.x迁移到3.x的使用转发功能时,我可以观察到一些不同的行为:
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
功能,以没有得到传递给重定向控制器PARAMS?
我认为你不需要添加param
。 forward
自动转发您的参数。这是可选的。如果添加它,它会重复的值。试试只用:
forward controller: 'foo', action : 'bar'