代码之家  ›  专栏  ›  技术社区  ›  masiboo

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

  •  0
  • masiboo  · 技术社区  · 7 年前

    我有以下类型的界面。有没有办法从其他类获取@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);
    }
    
    0 回复  |  直到 7 年前
        1
  •  1
  •   masiboo    7 年前

    在尝试了几种方法后,我发现了以下解决方案。我只想得到@Path(“/bucket definitions”)的值,也就是“bucket definitions”。它不是来自任何网站。所以这完全是我获取@Path annotation值的方法。其他专家可以给我一个更好的建议。希望这个解决方案能对其他人有所帮助。

    Annotation annotation = BucketDefinitionResource.class.getAnnotations()[0];
        if (annotation.toString().contains("Path")) {
            String SERVICE_NAME = annotation.toString().substring(annotation.toString().indexOf("/"), annotation.toString().indexOf(")"));
        }