我可以在grails中的两个类之间共享一个变量,比如在我的控制器中我想将变量processStart设置为true,并且一旦after save方法在我的控制器的域类中完成,我想将其设置为false像这样,
class EmployeeController{
def insert() {
for (i in 1..params.numberOfEmp.toInteger()) {
Employee emp = new Employee(params)
processStart = true // set this variable here
emp.save()
}
}
}
并在域类
中class Employee {
/** domain structure **/
def afterInsert () {
processStart = false // and after this, set this variable here
}
}
答案 0 :(得分:1)
尝试使用会话变量,不应该使用静态变量。
class EmployeeController{
def insert() {
for (i in 1..params.numberOfEmp.toInteger()) {
Employee emp = new Employee(params)
session['processStart'] = true // set this variable here
emp.save()
}
}
}
并在域类中:
class Employee {
/** domain structure **/
def afterInsert () {
session['processStart'] = false // and after this, set this variable here
}
}