我不想保存已编辑的域类,而是想使用我已制定的更改创建它的新实例。
def update =
{
def VariantInstance = Variant.get(params.id)
VariantInstance.properties = params
def NewVariantInstance = new Variant()
//Now Assign Variant Instance new Values
NewVariantInstance.Name = VariantInstance.Name
NewVariantInstance.LocationID = VariantInstance.LocationID
NewVariantInstance.aliases = VariantInstance.aliases
NewVariantInstance.closeToBoundary = VariantInstance.closeToBoundary
if (VariantInstance) {
if (!VariantInstance.hasErrors() && !NewVariantInstance.hasErrors()) {
println("no errors")
try {
NewVariantInstance.save()
}
catch (Exception ex)
{
println(ex.toString())
}
flash.message = "${message(code: 'default.updated.message', args: [message(code: 'Variant.uniqueIdentifyingName', default: 'Variant'), VariantInstance.id])}"
redirect(action: "list")
}
}
但是,当我运行此 A) 未保存新版本和 B) NewVariantInstance 没有 id。想法?