开发者

Grails controller syntax correction

开发者 https://www.devze.com 2023-03-09 13:17 出处:网络
I have something like this in my controller: class houseContro开发者_开发百科ller = { ... code ...

I have something like this in my controller:

class houseContro开发者_开发百科ller = {

...
code
...

if(params.answer == null)
redirect(action:'xxx')

...
code
...

}

My doubt is, the redirect in the middle of the controller. Does it need any 'return' or something similar due to not being at the end of the controller ? Or, after the redirect is done, all code after that is forgoten and not kept in memory ? My point, i dont wanna waste useless resources with bad-written code.


Any code that occurs after the redirect will be executed, but you will get an exception if you try to write to the response after performing the redirect.

In practice, you don't usually want to execute anything in the current action after performing the redirect, so I would rewrite the code above as:

if (params.answer == null)
  redirect(action:'xxx')
  return
}

...
code
---

or alternatively:

if (params.answer == null)
  redirect(action:'xxx')

} else {
  ...
  code
  ---
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号