0
我正在使用Play框架开发服务器。在我的几个方法中,我需要执行一些以前的操作(基本上是输入检查),所以我认为这样做的最佳方式是Action Composition。在Play框架中组合动作时重复相同动作
我可以用几个注解没有问题
@Action1 // <---------------------------------------- This action is executed
@Action2(value = "someValue") // <------------------- This action is executed
public CompletionStage<Result> doSomething() {
...
}
但只要我尽量重复这些动作具体行动不执行的一个:
@Action1 // <---------------------------------------- This action is executed
@Action2(value = "someValue") // <------------------- This action is not executed
@Action2(value = "someOtherValue") // <-------------- This action is not executed
public CompletionStage<Result> doSomething() {
...
}
我Action1
注释看起来像Play Framework example的VerboseAnnotation
,所以我不认为这是值得写在这里。正如我Action2
注释可以重复我已经宣布RepeatableAction2
注释是这样的:
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RepeatableAction2 {
Action2[] value() default {};
}
和Action2
看起来是这样的:
@With(Action2Impl.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(value = RepeatableAction2.class)
public @interface Action2 {
String value();
}
的方法是否正确注解。当我添加:
for (Method m : Application.class.getDeclaredMethods()) {
RequiredJsonValues reqs = m.getAnnotation(RequiredJsonValues.class);
for (RequiredJsonValue req : reqs.value()) {
System.out.println("Method: " + m + " annotation: " + req);
}
}
在方法的开始,我得到
Method: public java.util.concurrent.CompletionStage controllers.SomeController.doSomething() annotation: @util.Action2(value=someValue)
Method: public java.util.concurrent.CompletionStage controllers.SomeController.doSomething() annotation: @util.Action2(value=someOtherValue)
那我做错了吗?有没有其他方法可以用不同的值连续多次进行同一动作?