在使用 CRUD 脚手架之前无法保存域对象
我在 Grails 项目中的控制器遇到了最奇怪的问题。我正在尝试对域对象进行简单的更新。这是控制器的简化版本
def updateRecord = {
def foundHVT = Process.get(params.hvt)
foundHVT.summaryBy = params.summaryBy
foundHVT.catalogBy = params.catalogBy
foundHVT.editBy = params.editBy
foundHVT.produceBy = params.produceBy
foundHVT.correctedBy = params.correctedBy
// a bunch more of these
foundHVT.save(flush: true);
redirect (action:resource, id: params.hvt)
}
如果我运行应用程序的新实例并使用此控制器来更新对象,则它不起作用,对象不会保存。它在控制器中看起来很好。例如,我可以重新查询对象,更改就在那里,保存后。
现在事情变得奇怪了。如果我使用预设的脚手架编辑控制器并更新/保存域对象 - 然后切换回这个“updateRecord”控制器,它工作正常,直到我关闭它正在工作的服务器?!?
我意识到我错过了一些非常基本的东西,但我找不到它是什么。任何指导将不胜感激。
DM
I'm having the strangest problem with a controller in a Grails project. I am trying to do a simple update of a domain object. Here is a simplified version of the controller
def updateRecord = {
def foundHVT = Process.get(params.hvt)
foundHVT.summaryBy = params.summaryBy
foundHVT.catalogBy = params.catalogBy
foundHVT.editBy = params.editBy
foundHVT.produceBy = params.produceBy
foundHVT.correctedBy = params.correctedBy
// a bunch more of these
foundHVT.save(flush: true);
redirect (action:resource, id: params.hvt)
}
If I run the a new instance of the application of and use this controller to update an object, it doesn't work, the object doesn't save. It will look fine within the controller. I can, for example, re-query the object and the changes are there, post save.
Now here's where it gets weird. If i use the preset scaffold edit controller and update/save an domain object -- and then switch back to this "updateRecord" controller it works FINE until i shut down the server it is working on?!?
I realize I am missing something very basic, but I can't find what it is. Any guidance would be most graciously appreciated.
DM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 HVGOTCODES 所指出的,Grails Clean 似乎已经修复了该控制器出现的任何奇怪问题。
As HVGOTCODES noted Grails Clean seems to have fixed whatever weirdness was going on with this controller.
如果控制器还没有正常的入口点,请尝试在控制器中放入“defscaffold=true”。
try putting a "def scaffold=true" in your controller if it does not already have the normal entry points.
也许脚手架
save
填补了一些您没有填补的领域。可能出现的问题:
请按照 Grails 的方式检查
save()
结果并呈现foundHVT.errors
。将failOnError: true
参数添加到save()
或仅检查foundHVT.hasErrors()
。查看foundHVT.errors.allErrors
是否存在验证问题。为什么不
foundHVT.properties = params
?没有
foundHVT
是什么?Probably scaffolding
save
fills some field that you don't.Possible problems:
Do check
save()
result and renderfoundHVT.errors
the way Grails does. AddfailOnError: true
parameter tosave()
or just checkfoundHVT.hasErrors()
. Look atfoundHVT.errors.allErrors
for validation problems.Why not
foundHVT.properties = params
?What is there is no
foundHVT
?