1

Im new to grails and using version of 2.1.1

I have been working params for passing data from view to controller ie I have submit URL to controller :

http://example.com/save?param1=one&param2=two&param3=three&param4=four

and then the URL will handle with save() in controller, I use it and I will passing some param into another view. Code like this

redirect action: "index", params:params

but when I success to redirect, all param is include (param1,param2, param3 & param4)

http://example.com/index?param1=one&param2=two&param3=three&param4=four

I just want to have param1 in my index view. Currently I do this remove param using :

params.remove("param2")
params.remove("param3")
params.remove("param4")

Is there any simply way to remove multiple params in grails?

4

2 回答 2

4

伊戈尔的答案可能是您想要的,但您可以在一行中删除多个键:

['param1', 'param2', 'param3'].each { params.remove it }

或者您可以删除除一个以外的所有内容:

params.keySet().asList().each { if ('param1' != it) params.remove(it) }

asList()用来复制集合以避免 ConcurrentModificationException

于 2013-05-06T04:49:33.740 回答
3

如果您只需要一个参数,最简单的方法是创建一个新对象:

redirect action: "index", params: [param1: params.param1]
于 2013-05-06T04:46:54.343 回答