本文介绍了在Grails中是否有像onLoad()这样的域类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计,
我有一个以下的域类:
class Product {
String name,
String productRecord,
static transients = ['productRecord']
}
productRecord是根据Product实例的id自动生成的字段。
所以我一直在想,是否有一个地方会在域实例加载时产生productRecord数字时自动调用?
最好的方法是做什么?
解决方案您可以利用:
查看一些例子的文档。
Guys,
I have a following domain class:
class Product { String name, String productRecord, static transients = ['productRecord'] }
productRecord is a field which is generated automatically based on the id of the Product instance.
So I've been thinking, is there a place which will be automatically called when a domain instance is load to generate the productRecord number?
What's the best way to do that?
解决方案You can probably leverage the built-in Domain Events:
Have a look at the docs for some examples.
这篇关于在Grails中是否有像onLoad()这样的域类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!