render:
界面跳转(url不变)、向网页输出数据(接口都用这个)
render 之后,程序会继续执行,但是 后面不能使用 redirect 、respond
例如:
def test()
{
def json = new JSON(School.findAll().first())
json.setExcludes(Student.class,["class","school"])
render json
println 'xxxxxxxxxxxxxxxx'
redirect view:'index'
}
网页:
{"class":"com.myfund.School","id":1,"name":"fwe","students":[{"id":2,"age":13,"name":"13"},{"id":1,"age":12,"name":"12"}]}
控制台:
redirect:
重定向,url会改变
respond之后,程序会继续执行,后面不能再次使用redirect,虽可以使用render、respond、但是没有任何作用
respond:
向页面返回数据
respond之后,程序会继续执行,后面可以使用render、redirect,但respond无作用
本文介绍了在Grails框架下,render与redirect两种页面处理方式的不同之处。render主要用于界面跳转(URL不变)及向网页输出数据,之后程序会继续执行但不能再使用redirect或respond。redirect用于重定向并改变URL,而respond则用于向页面返回数据,其后虽然程序继续执行,但respond不再生效。

360

被折叠的 条评论
为什么被折叠?



