在我的控制器中将参数从一种方法传递给另一种方法 [英] Passing parameters from one method to another in my controller
问题描述
在我的def contentPerson
中保存参数方法 saveperson
。有谁知道如何保存参数 - 找不到我的方法 savework
def saveperson(Person personIntance){
def contentPerson = personInstance.save(flush:true)
重定向(controller:'Person',action:'creatework')
flash.message =我自动选择人员ID;
$ b $ def savework(Work workInstance,contentPerson){
def work1 = new Work(name:params.name,person:contentPerson,profession:params.profession)
work1.save(flush:true)
}
讯息:
没有这样的属性:
contentPerson
重定向会创建一个全新的调用,因此它是一个完全不同的上下文。
你可能想试试这个:
redirect(controller:'Person',action:'creatework',params :[contentPerson:contentPerson])
或将其保存在闪存中,如下所示:
flash.contentPerson = contentPerson
您可以将其用于其他请求,例如:
flash.contentPerson
但是你应该避免使用flash消息。所以传递参数更好。
Save parameters of a method to another.
Save parameters of the person in my def contentPerson
in my method saveperson
. Does anyone know how to save parameters - no found of my method savework
def saveperson(Person personIntance) {
def contentPerson =personInstance.save(flush:true)
redirect(controller:'Person', action:'creatework')
flash.message="I automatically select the person id";
}
def savework(Work workInstance,contentPerson) {
def work1 = new Work(name:params.name,person:contentPerson, profession:params.profession)
work1.save(flush:true)
}
Message:
No such property:
contentPerson
redirect makes a completely new call, so it is a completely different context. you might want to try this:
redirect(controller:'Person', action:'creatework', params:[contentPerson: contentPerson])
or save it in flash, like this:
flash.contentPerson = contentPerson
you can use it for another request, like this:
flash.contentPerson
but you should avoid flash messages. so better pass parameters.
这篇关于在我的控制器中将参数从一种方法传递给另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!