tôi gọi một phương pháp chỉ số trong một bộ điều khiểnnếu phát biểu trong một GSP trong Grails
def index() {
childInstance = Child.get(params.id)
if(childInstance){
System.out.println("CHILD" + childInstance.firstname)
def messages = currentUserTimeline()
[profileMessages: messages,childInstance:childInstance]
} else {
def messages = currentUserTimeline()
[profileMessages: messages]
System.out.println("ALL")
}
}
trong trang GSP Tôi có
${childInstance.firstname}
nào nếu tôi vượt qua một childInstance này là tốt nhưng nếu tôi tôi không nhận được một 500 vì một con trỏ null là có một cách tôi có thể làm một tuyên bố nếu trong một gsp vì vậy tôi có thể làm điều này
if(childInstance){
${childInstance.firstname}
} else {
All
}