我希望能够添加以下属性 updatedBy
我的大部分 GORM 对象。我正在考虑使用 AST 转换。类似于此处描述的内容:http://www.zorched.net/tag/grails/
但我需要在 gorm Hook 上设置此属性 beforeUpdate()
和 beforeInsert()
就像是
def beforeUpdate() {
updatedBy = springSecurityService.currentUser;
}
这就是我挣扎的地方。任何帮助表示赞赏?
最佳答案
将其封装为每个域类实现或扩展的特征或抽象类。如果您使用的是足够新的 Groovy 版本以支持特征,则最好是特征。如果没有,像这样的抽象类
class Audited {
def springSecurityService
def updatedBy
def beforeUpdate() {
updatedBy = springSecurityService.currentUser
}
}
关于grails - 为所有 GORM 对象添加属性和方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28242706/