[英]Groovy Grails handle controller parameters
I do an AJAX request from mt front-end with array as parameter. 我从mt前端做一个AJAX请求,数组作为参数。 Example of the array: 数组示例:
arr = [13, 56, 43]
When in Grails controller I print params I get arr[]:[13, 56, 43]
. 当在Grails控制器中我打印参数时,我得到了arr[]:[13, 56, 43]
。 However, when in front-end array consists of only one element ( arr = [25]
, for instance), then in controller I get arr[]:32
. 但是,当前端数组只包含一个元素(例如arr = [25]
)时,在控制器中我得到arr[]:32
。 However, I need the parameter to be the list, like arr[]:[32]
. 但是,我需要参数作为列表,如arr[]:[32]
。 How can I do that? 我怎样才能做到这一点?
In the controller you can use 在控制器中,您可以使用
params.list('arr[]')
This will always return a list, with zero, one or more than one element, unlike the basic 这将始终返回一个列表,其中包含零个,一个或多个元素,与基本元素不同
params.'arr[]'
which gives you null
if there are no arr[]
parameter values, the single value if there is one, and a list if there is more than one. 如果没有arr[]
参数值,则为null
如果有值则为单值,如果有多个,则为列表。
I think In the controller you can use 我认为在控制器中你可以使用
List arr = []
arr = params.list
or 要么
def arr
arr = params.list as List
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.