Grails 域 Class 事件
Grails Domain Class Events
我是 Grails 的新手,我对域 class 挂钩感到好奇,例如 beforeinsert()
、beforeupdate()
、...等
但是我找不到关于如何使用此功能的好方法 resource/documentation。
谁能给我一个好的资源或向我解释一下这是如何工作的?
这些方法是一种挂接到域实例生命周期的方法。
grails gorm documentation 非常清晰和精确,所以我将引用那里的定义,但我创建了一个状态图来描述图片:
- beforeInsert - Executed before an object is initially persisted to the database. If you return false, the insert will be cancelled.
- beforeUpdate - Executed before an object is updated. If you return false, the update will be cancelled.
- beforeDelete - Executed before an object is deleted. If you return false, the delete will be cancelled.
- beforeValidate - Executed before an object is validated
- afterInsert - Executed after an object is persisted to the database
- afterUpdate - Executed after an object has been updated
- afterDelete - Executed after an object has been deleted
- onLoad - Executed when an object is loaded from the database
我是 Grails 的新手,我对域 class 挂钩感到好奇,例如 beforeinsert()
、beforeupdate()
、...等
但是我找不到关于如何使用此功能的好方法 resource/documentation。
谁能给我一个好的资源或向我解释一下这是如何工作的?
这些方法是一种挂接到域实例生命周期的方法。
grails gorm documentation 非常清晰和精确,所以我将引用那里的定义,但我创建了一个状态图来描述图片:
- beforeInsert - Executed before an object is initially persisted to the database. If you return false, the insert will be cancelled.
- beforeUpdate - Executed before an object is updated. If you return false, the update will be cancelled.
- beforeDelete - Executed before an object is deleted. If you return false, the delete will be cancelled.
- beforeValidate - Executed before an object is validated
- afterInsert - Executed after an object is persisted to the database
- afterUpdate - Executed after an object has been updated
- afterDelete - Executed after an object has been deleted
- onLoad - Executed when an object is loaded from the database