@with 注释到底是做什么的?(播放框架) [英] what exactly does the @with annotation do? (Play Framework)

查看:48
本文介绍了@with 注释到底是做什么的?(播放框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太明白@with 注释的作用.

I don't quite understand what the @with annotation does.

在 Play framework 站点中,它是这样写的:

in the Play framework site, it is written :

我们可以使用@With注解来注解控制器播放调用相应的拦截器

we can annotate the controllers using the @With annotation to tell Play to invoke the corresponding interceptors

它和继承一样吗?它会调用给定类参数的@before 吗?它到底是做什么的?

is it the same as inheritance ? will it invoke @before of the given class parameter ? what exactly does it do ?

推荐答案

我能描述它的最好方式是,它在你的控制器级别为你的拦截器提供了多重继承.拦截器是 @Before@After 注释.

The best way I can describe it, is that it kind of gives you multiple inheritance at your controller level for your interceptors. Interceptors being the @Before, @After annotations.

因此你可以

  • 定义一个控制器来处理你的安全区域@Before注解
  • 定义一个控制器,用于使用 @Before
  • 为共享操作注入静态数据
  • define a controller that dealt with your secure area @Before annotations
  • define a controller that dealt with injecting your static data for shared actions using @Before

然后您可以定义一个或多个控制器来包含您的所有操作,并使用 @With 注释来使用上述两个控制器.这意味着您可以干净地分离代码,而不必依赖继承来执行 @Before 注释.

you could then define a controller or controllers that contained all your actions, and use the @With annotation to make use of the two controllers described above. It means you can separate your code out cleanly, and not have to rely on inheritance to execute the @Before annotations.

这篇关于@with 注释到底是做什么的?(播放框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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