我在控制器中调用了一个索引方法。
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")
}
}
在GSP页面中,我有以下内容:
${childInstance.firstname}
如果我传递一个childInstance,那么一切都好,但是如果我不这样做,由于空指针我会得到500错误,有没有办法在gsp中做一个if语句来解决这个问题?
if(childInstance){
${childInstance.firstname}
} else {
All
}