得到一個域的特定實例我有一個要求這樣的方法一個GSP文件:Grails中
<g:link id="${child.id}" action="callChildProfile" controller="profile">${child.firstname}</g:link>
調用該方法
def callChildProfile(Long id){
childInstance = Child.get(id)
System.out.println(childInstance.firstname + " child instance")
redirect(action: "index")
}
此方法設置一個子實例到公共變量稱爲子實例,但是當重定向發生時,變量被重置。 我重定向的原因是因爲我想從這個控制器加載索引頁面。
指數看起來像這樣:
def index() {
def messages = currentUserTimeline()
[profileMessages: messages]
System.out.println(childInstance + " child here")
[childInstance : childInstance]
}
但這是否意味着每次我打電話索引我都要給它一個長ID? – Sagarmichael
我在答案中寫了一個選擇 –