所以我试图为
创建一个别名
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiResponses {
ApiResponse[] value();
}
我尝试过的,
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface targetTest {
@AliasFor(annotation = ApiResponses.class, attribute="value")
ApiResponse[] value()
default {
@ApiResponse(code = 200, message = "test1"),
@ApiResponse(code = 400, message = "test2"),
@ApiResponse(code = 404, message = "test3"),
@ApiResponse(code = 500, message = "test4")
};
}
当我使用时,这不会覆盖 ApiResponses 注释
@targetTest
doSomething()
有什么建议吗?
您需要在 TargetTest
上添加 @ApiResponses
@Target({ANNOTATION_TYPE, METHOD})
@Retention(RUNTIME)
public @interface ApiResponses {
ApiResponse[] value() default {};
}
@Target(METHOD)
@Retention(RUNTIME)
@ApiResponses
public @interface TargetTest {
@AliasFor(annotation = ApiResponses.class)
ApiResponse[] value() default {...};
}
我是一名优秀的程序员,十分优秀!