我有一个针对DB2数据库的相当简单的Grails应用程序。除非我尝试更新记录,否则一切正常。 show()和edit()能够找到记录,但更新失败,说它无法找到。这是编辑:
def edit()
{
def flatAdjustmentInstance = FlatAdjustment.get( new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"]) ) //here are your inbound params
if(!flatAdjustmentInstance)
{
flash.message = "MRI Modifier Record not found with ${params}"
redirect(action:"list")
}
else
{
return [ flatAdjustmentInstance: flatAdjustmentInstance]
}
}
现在更新()
def flatAdjustmentInstance = FlatAdjustment.get( new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"]) ) //here are your inbound params
//def flatAdjustmentInstance = new FlatAdjustment(compPayeeID: params["compPayeeID"], effectiveQuarterBeginDate: params["effectiveQuarterBeginDate"])
if (!flatAdjustmentInstance)
{
flash.message = message(code: 'default.not.found.message', args: [message(code: 'flatAdjustment.label', default: 'FlatAdjustment'), params])
redirect(action: "list")
return
}
正如我所说,所有控制器方法/闭包都以相同的方式创建域对象的实例,并且除了update()之外所有操作都正确。有什么想法吗?
答案 0 :(得分:0)
.get()
根据其ID检索现有对象。您无法将新对象传递给该方法。
FlatAdjustment flatAdjustmentInstance = FlatAdjustment.findByCompPayeeIDAndEffectiveQuarterBeginDate(params.compPayeeID, params.date("effectiveQuarterBeginDate", "INSERTYOURDATEFORMATHERE"))
答案 1 :(得分:0)
我想出了这个,这是一个真正的骨头错误。我创建的表单是传递compPayeeID,但由于该字段不能被用户编辑,我将其从输入更改为textField。这意味着不再与grails params对象传递。我把它改回来,把字段设置为只读,现在一切都很顺利。