您可以強制Grails中的DomainClass.get(id)功能從數據庫中提取新實例,而不是使用先前在會話中檢索到的本地副本?Grails - 從數據庫中檢索新鮮實例
我想比較,如果該實例的屬性發生了變化:
例:
def myInstance = MyClass.get(params.id)
myInstance.properties = params.data // updates the instance, but does not save it
// stuff happens
def myDbInstance = MyClass.get(params.id) // would like this to pull a fresh copy from the database, unchanged to allow for comparison
if(myDbInstance.value != myInstance.value) {
// do something if has changed
}
謝謝。
查看['getPersistentValue()'](http://grails.org/doc/latest/ref/Domain%20Classes/getPersistentValue.html)和['isDirty()'](http:// grails .ORG/DOC /最新/ REF /域%20Classes/isDirty.html)。 – dmahapatro 2014-09-02 15:37:23