我需要与不需要持久化的 grails 域对象类似的对象。为了我不必为任何字段更改在 2 个地方进行更改,扩展域类是否是一个好主意,以便我可以获得单组字段的好处。尽管所有相关的对象和集合都需要重做。
问问题
783 次
1 回答
2
@cfrick 很到位。Groovy 特征是一个非常好的方法。你可以在这里得到一个完整的例子(我知道这个项目的名字不好)。这是一个简单的例子:
// MyTrain.groovy: Put this in src/main/groovy/my/package
package my.package
trait MyTrait {
Integer number
String something
}
// MyDomainClass.groovy: This goes with the other domain classes.
package my.package
class MyDomainClass implements MyTrait {
/*
* number and something properties are available here.
* They become table columns.
*/
static constraints {
/*
* And you can place constraints on them,
* as it they had been declared in this class.
*/
}
}
于 2016-01-06T15:15:22.283 回答