Grails 从文件中读取数据并将其存储在对象中

Grails read data from file and store it in an object

我正在尝试读取控制器中的文件并将一些数据存储在对象中,但我无法正确保存它。谁能帮忙?我是 Groovy/Grails 的新人...

File generals = new File("C:/Grails/Grails-3.3.0/ggts/Test/data.txt")
def line = generals.readLines()
def date = new SetDate(params)
date.save()

date.title = ${line[0]}
date.location = ${line[1]}
date.description = ${line[2]}
date.name = ${line[3]}
date.email = ${line[4]} 
date.save()

如果您想使用 string interpolation,您可以将 ${line[0]} 更改为 "${line[0]}" 等等。

因为line是一个String列表,把${line[0]}改成line[0]也可以。