2016-01-06 78 views
0

將方法的參數保存到另一個方法中。在控制器中將參數從一種方法傳遞到另一種方法

在我的方法saveperson中保存人員的參數在我的def contentPerson中。有誰知道如何保存參數 - 沒有發現我的方法的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) 
} 

消息:

沒有這樣的屬性:contentPerson

+0

您是否將它用作腳本?或上課?因爲'contentPerson'不在範圍內。 – Rao

+0

你打電話給'savework()'的地方? – doelleri

+0

您可以通過包括如何調用它來更新該文章嗎?全堆棧跟蹤? – Rao

回答

1

重定向使一個完全新的呼叫,所以它是一個完全不同的背景。 你可能想試試這個:

redirect(controller:'Person', action:'creatework', params:[contentPerson: contentPerson]) 

或將其保存在閃存中,這樣的:

flash.contentPerson = contentPerson 

,你可以使用它的另一個請求,就像這樣:

flash.contentPerson 

但你應該避免使用Flash消息。所以傳遞參數更好。

+0

感謝您回答我的問題使用隱藏 –

相關問題