如何影响播放控制器中的重定向行为? [英] How can I influence the redirect behavior in a play-controller?
问题描述
在游戏中,您始终遵循 Redirect-After-Pattern 如果从控制器的公共方法调用.在大多数情况下,这是一种良好的行为,但有时可能会令人讨厌.
因此,我试图找出它在游戏1.1中的工作原理!:
基本的是一些字节码增强,这是在play.classloading.enhancers.ControllersEnhancer
中完成的.
在那里,您会发现默认行为仍然存在一些例外情况:
In play you always follow the Redirect-After-Post-Pattern if you call from a public-method of a controller. This is in most cases a good behavior, but sometime it could be nasty.
So I tried to find out how it works in play 1.1!:
The basic is some byte-code-enhancement, which is done in play.classloading.enhancers.ControllersEnhancer
.
There you can find that there still exists some exceptions of the default behavior:
- 如果您的方法由包
play.mvc
中的注释(例如,Before-annotation)注释. - 您使用
ByPass
-Annotation注释您的操作,此Annotation必须是内部类,因此名称以$ByPass
结尾.
- If your method is annotated by an annotation from the package
play.mvc
, for example the Before-annotation. - You annotate your action with the
ByPass
-Annotation, this Annotation must be an inner-class so the name endsWith$ByPass
.
如果您总是想抑制重定向,则两种解决方案都可以.但是,如果您只想在特殊情况下这样做怎么办?
然后,您可以拨打ControllerInstrumentation.initActionCall()
.
Both solutions are fine if you always want to suppress the redirect. But what if you only want to do it in special situation?
Then you can call ControllerInstrumentation.initActionCall()
.
我没有找到关于它的描述,我只是分析代码.那么我的结论是正确的还是有任何弊端?
I don't find a description about it, I just analyze the code. So are my conclusion correct or have the any drawbacks?
推荐答案
对于我所知,您的假设是正确的.
For what I know you assumptions are correct.
那就是说,据我了解,您想要一个在执行后结束并且什么都不返回的方法?不要在末尾添加任何"render"调用(或对另一个方法的任何调用),这应该可以工作.我将其用于cron作业.
That said, for what I understand you want a method that ends after execution and returns nothing? Don't add any "render" call at the end (or any call to another method) and that should work. I use it for cron jobs.
这篇关于如何影响播放控制器中的重定向行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!