Groovy Grails Knob Controller Options

I am making an AJAX request from mt front-end with an array parameter. Array example:

arr = [13, 56, 43] 

When I print params in the Grails controller, I get arr[]:[13, 56, 43] . However, when there is only one element in the interface array ( arr = [25] , for example), then in the controller I get arr[]:32 . However, I need a parameter that should be a list, for example arr[]:[32] . How can i do this?

+6
source share
2 answers

In the controller you can use

 params.list('arr[]') 

This will always return a list with zero, one or more items, unlike the main

 params.'arr[]' 

which gives you null if there are no values โ€‹โ€‹for the arr[] parameter, the only value if there is one, and a list if there are more.

+8
source

I think in the controller you can use

 List arr = [] arr = params.list 

or

 def arr arr = params.list as List 
0
source

Source: https://habr.com/ru/post/948078/


All Articles