1

我对动态变量名有疑问

我有像这样的表单参数

ip1
ip2
ip3
dns1
dns2
...

我知道有多少,但我不知道如何在控制器中创建变量名

def ipcount = params.count
    for (i = 1; i = ipcount ; i++ ){
         def systems = new Ip() 
         systems.inetAddress = params.ip+${i}  <---- How do I create these variable name?
                 ....
4

1 回答 1

5

只需将它们用双引号括起来:

def ipcount = params.int( 'count' )
def systemsList = (1..ipcount).collect { i ->
    def systems = new Ip() 
    systems.inetAddress = params."ip${i}"
    ...
    systems
}
于 2013-10-17T09:14:56.193 回答