我在GSP页面调用一个控制器if语句在GSP中的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")
}
}
中的索引方法我有
${childInstance.firstname}
哪个,如果我传递一个childInstance,这是好的,但如果我我没有得到一个500,因为空指针是否有办法,我可以做一个gsp的if语句,所以我可以做到这一点
if(childInstance){
${childInstance.firstname}
} else {
All
}