machineInstanceInstance

machineInstanceInstance

我有一个名为MachineInstance的Grails类和以下代码

machineInstanceInstance.reservationId = reservation.reservationId
println "-------"+reservation.reservationId+"====="+machineInstanceInstance.reservationId

我专门为对象分配reservationId,它也被打印出来,但是在它的正下方,我有以下两行代码。这两个输出错误都说Field error in object 'com.ch.MachineInstance' on field 'reservationId': rejected value [null]
machineInstanceInstance.errors.each{println it}
if (machineInstanceInstance.hasErrors()) { more code   }

最佳答案

如果使用自动绑定(bind),然后在实例中插入一些数据,则需要对实例进行validate

试试这个

machineInstanceInstance.validate()
machineInstanceInstance.errors.each{println it}
if (machineInstanceInstance.hasErrors()) { more code   }

08-05 01:29