亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從其他類獲取Java接口@Path值

如何從其他類獲取Java接口@Path值

慕森卡 2022-06-23 15:53:54
我有以下類型的界面。有沒有辦法從其他類中獲取 @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);}
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

在嘗試了多種方式后,我發現了以下解決方案。我只對獲取 @Path("/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(")"));

    }


查看完整回答
反對 回復 2022-06-23
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號