我遇到动态变量名称的问题
我有像
这样的表单参数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?
....
答案 0 :(得分:4)
将它们用双引号括起来:
def ipcount = params.int( 'count' )
def systemsList = (1..ipcount).collect { i ->
def systems = new Ip()
systems.inetAddress = params."ip${i}"
...
systems
}