如何从其他类获取Java接口@Path值

问题描述 投票:0回答:1

我有以下类型的界面。有没有办法从其他类中获取@Path(“/ bucket-definitions”)值“/ bucket-definitions”?

@Path("/bucket-definitions")
@Api(
    value = "Bucket definition",
    authorizations = {@Authorization("token")}
)
public interface BucketDefinitionResource {
    @GET
    @Path("/{operator-id}")
    @Produces({"application/json"})
    @ApiOperation(
        value = "Get all bucket definitions.",
        notes = "Returns all bucket definitions.",
        response = BucketDefinitionList.class
    )
    BucketDefinitionList get(@ApiParam(value = "Bucket definitions of the operator to be fetched.",required = true) @PathParam("operator-id") String var1, @ApiParam(value = "Page number",required = false) @DefaultValue("1") @QueryParam("page") Integer var2, @ApiParam("Items per page") @DefaultValue("20") @QueryParam("per_page") Integer var3);
}
java interface annotations
1个回答
0
投票

在尝试了几种方法之后我发现了以下解决方案。我只对获取@ bucket(“/ bucket-definitions”)的值为“bucket-definitions”感兴趣。它不是来自任何网站。所以这完全是我获取@Path注释值的方法。其他专家可以建议我一个更好的方法。希望这个解决方案对其他人有所帮助。

Annotation annotation = BucketDefinitionResource.class.getAnnotations()[0];
    if (annotation.toString().contains("Path")) {
        String SERVICE_NAME = annotation.toString().substring(annotation.toString().indexOf("/"), annotation.toString().indexOf(")"));
    }
© www.soinside.com 2019 - 2024. All rights reserved.