Playframework 为什么@Before(only={quot;method";})注释没有级联到正在使用的子类!框架

Playframework 为什么@Before(only={quot;method";})注释没有级联到正在使用的子类!框架,playframework,Playframework,这出戏!文档表明@Before过滤器级联到子类控制器() 假设我有: public class BaseController extends Controller { @Before(only={"show"}) public static void check() { Logger.info("checking..."); } } public class Users extends BaseController { public static

这出戏!文档表明@Before过滤器级联到子类控制器()

假设我有:

public class BaseController extends Controller {
    @Before(only={"show"})
    public static void check() {
        Logger.info("checking...");
    }
}

public class Users extends BaseController {
    public static void show(Long id) {

    }
}
当调用Users#show时,我希望显示“checking…”,但事实并非如此。将@Before过滤器移动到Users类中会显示消息。删除唯一的修改器也会导致显示消息


为什么唯一的修饰符不与@Before过滤器一起级联

我相信“only”适用于声明它的类,在本例中是BaseController。标记解析后,play将在BaseConroller中查找show方法

我相信“only”适用于声明它的类,在本例中是BaseController。标记解析后,play将在BaseConroller中查找show方法

相反,您可以制作自己的注释并将其放在类中

@With(NewAnnonation.class)
public class YourClass() extends Controller { methods}
然后,您可以在想要创建的类上使用新注释

public class NewAnnotation() extends Controller {
@Before( only = { "YourClass.method1", "YourClass.method2", "SomeOtherClass.method"})
public static void doSomeThingBeforeMethods() {insert code :)}

相反,您可以创建自己的注释并将其放在类中

@With(NewAnnonation.class)
public class YourClass() extends Controller { methods}
然后,您可以在想要创建的类上使用新注释

public class NewAnnotation() extends Controller {
@Before( only = { "YourClass.method1", "YourClass.method2", "SomeOtherClass.method"})
public static void doSomeThingBeforeMethods() {insert code :)}

对我来说也是这样。我尝试向BaseController添加一个“show”方法,但@Before过滤器仍然被忽略。所以我还是被卡住了,这也是我的感觉。我尝试向BaseController添加一个“show”方法,但@Before过滤器仍然被忽略。所以我还是被卡住了。