为什么在 grails 中转发和重定向不会停止初始动作的执行? [英] Why forward and redirect in grails don't stop initial action execution?

查看:13
本文介绍了为什么在 grails 中转发和重定向不会停止初始动作的执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解了 forwardredirect 在 Grails 中,不明白为什么下面的代码会打印foo".

I read about forward and redirect in Grails and don't understant why the code bellow prints "foo".

见:

def bar = {
   redirect (controller: "public", action: "index") // same happens with forward
   println "foo" // prints this in console?? WHY?
}

在我看来重定向/转发必须跳过当前方法的执行...

In my opinion redirect/forward must skip current method execution...

这是错误还是我理解错误?

Is this a bug or I understand the concept wrong?

推荐答案

因为这些是 只是函数调用 - 他们不能从调用函数(您的操作)中退出.只需将 return 放在后面即可.

Because these are just function calls - they can't exit from a calling function (your action). Just put return afterwards.

这篇关于为什么在 grails 中转发和重定向不会停止初始动作的执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆