Grails Can';不初始化临时成员吗?
在grails 2.0.4中,我有一个域类,如下所示:Grails Can';不初始化临时成员吗?,grails,Grails,在grails 2.0.4中,我有一个域类,如下所示: class Foo { String pres String temp static transients = ['temp'] def beforeInsert = { println "pres: ${pres}" println "temp: ${temp}" } } 在BootStrap.groovy中: def f1 = new Foo(pres: "
class Foo {
String pres
String temp
static transients = ['temp']
def beforeInsert = {
println "pres: ${pres}"
println "temp: ${temp}"
}
}
在BootStrap.groovy中:
def f1 = new Foo(pres: "p1", temp: "t1")
f1.save()
def f2 = new Foo(pres: "p2")
f2.temp = "t2"
f2.save()
然后grails run应用程序,我得到:
pres: p1
temp: null
pres: p2
temp: t2
f1和f2之间有什么区别,不能初始化临时成员吗?升级到Grails 2后,我遇到了同样的问题。如果需要更多信息,请参阅以下两个JIRA条目:
但是,最终,我不得不求助于您在示例中所做的相同工作。允许您覆盖默认行为。它通常用于禁用默认情况下可绑定的属性的数据绑定,但我相信您也可以用另一种方式使用它。我想知道这是否与v2.0.2()中的数据绑定更改有关,其中默认情况下不包括瞬态的数据绑定