【问题标题】:GET api with Retrofit使用 Retrofit 获取 api
【发布时间】:2017-03-09 17:01:28
【问题描述】:

我有一个网络服务链接,我想用不同的 customerId 以

的形式点击它
 http://apidev.myserver.com.au:8980/TestService/rest/TestService/jobs/bycustid/customerId

如何附加 customerId 的值?

这是我的基本网址:

 http://apidev.myserver.com.au:8980/TestService/rest/TestService/

这就是我的调用界面的样子:

interface CustomerJobs {
    @GET("jobs/bycustid/11726")
    Call<CustomerJobsPojo> getCustomerJobs();
}

【问题讨论】:

  • Retrofit 网站上的第一个示例回答了您的问题。 @Path。你试过了吗?
  • 该死,感觉好蠢! ..我应该删除这个问题还是让它消失?
  • 这是一个很好的问题,只是记得在你提问之前做更多的研究
  • 我的错……:|

标签: android retrofit retrofit2


【解决方案1】:

正如doc 所说:

interface CustomerJobs {

    @GET("jobs/bycustid/{id}")
    Call<CustomerJobsPojo> getCustomerJobs(@Path("id") int id);

}

【讨论】:

  • 让我试试这个。
  • 可能需要Integer id
  • @agonist_ - stackoverflow 不会让我在不到 10 分钟的时间内接受你的回答,尽管我在一开始就知道你的回答是正确的。我等了 9 分钟,然后回到我的工作并忘记接受:)
【解决方案2】:

试试@Path注解

interface CustomerJobs {
    @GET("jobs/bycustid/{id}")
    Call<CustomerJobsPojo> getCustomerJobs(@Path("id") String id);
}

【讨论】:

    【解决方案3】:

    你可以像嵌入一样

    @GET("jobs/bycustid/{custId}")
         Call<CustomerJobsPojo> groupList(@Path("custId") int custId);
    

    【讨论】:

      【解决方案4】:

      是的,您可以使用动态网址

      interface CustomerJobs {
      
          @GET("jobs/bycustid/{customerid}")
          Call<CustomerJobsPojo> getCustomerJobs(@Path("id") int customerid);
      
      }
      

      参考this

      【讨论】:

        猜你喜欢
        • 2021-12-23
        • 2014-03-14
        • 2021-08-19
        • 1970-01-01
        • 2018-08-27
        • 2019-08-11
        • 2022-01-23
        • 2020-05-27
        • 2021-05-30
        相关资源
        最近更新 更多