在 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: "p1", temp: "t1")
f1.save()
def f2 = new Foo(pres: "p2")
f2.temp = "t2"
f2.save()
然后 grails run-app,我得到了:
pres: p1
temp: null
pres: p2
temp: t2
f1 和 f2 有什么区别,不能初始化瞬态成员?