跨控制器变量 [英] Cross controller variables
本文介绍了跨控制器变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在阅读这篇文章后,我想知道在我的应用程序中超类控制器"的最佳方法是什么.
After reading this post I was wondering what would be the best way to "superclass the controller" in my app.
我有几个要求不同安全性的控制器,但是它们在模板中使用相同的一组持久变量.这看起来像是正确的方法吗?
I have several controllers that require different security, but, they use the same set of persisted variables in templates. Does this look like the right approach?
public class Globals extends Controller {
@Before
static void setGlobals() {
renderArgs.set("foo","bar");
}
}
然后为控制器@With拦截器添加注释
Then annotate controllers @With interceptor
@With([Globals.class, mySecurity.class])
public class Application extends Controller {
// my methods
}
很酷吗?
推荐答案
是的,建议使用@With注释.但是如果没有其他副作用,您可以自由使用继承
Yes, using @With annotation is the way that play recommended. But you are free to use inheritance if no other side effect
这篇关于跨控制器变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文