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)
那我做錯了嗎?有沒有其他方法可以用不同的值連續多次進行同一動作?