我对动态变量名称有疑问
我有像

ip1
ip2
ip3
dns1
dns2
...
这样的表单参数
我知道多少,但我不知道如何在 Controller
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?
                 ....
中创建变量名

最佳答案

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

def ipcount = params.int( 'count' )
def systemsList = (1..ipcount).collect { i ->
    def systems = new Ip()
    systems.inetAddress = params."ip${i}"
    ...
    systems
}

10-08 13:23