Retrofit2 将列表作为 Url 参数传递
Retrofit2 Passing List as Url parameter
我正在尝试使用字符串列表发出 GET 请求。
像这样表示列表的改造;
/endpoint?GTIN=111>IN=222
但是服务器(Springboot)只给出最后一个的结果。
它适用于此
/endpoint?GTIN=111,222
有没有办法在改造中做后者?
您可以尝试使用 Retrofit 的 @Url
注释来生成所需的 URL。
在您的服务接口文件中对您的 API 方法进行更改,
public interface YourServiceInterface {
@GET() // DO NOT pass any arguments here
Call<YourResponseObject> foo(@Url String url); // use @Url annotation here
}
在您的 Activity 或片段中。
String url = BASE_URL + "/endpoint?GTIN=111,222"; // https://example.com/endpoint?GTIN=111,222
YourServiceInterface api = ....;
Call<YourResponseObject> call = api.foo(url);
call.enqueue(/* implementation */);
我正在尝试使用字符串列表发出 GET 请求。
像这样表示列表的改造;
/endpoint?GTIN=111>IN=222
但是服务器(Springboot)只给出最后一个的结果。
它适用于此
/endpoint?GTIN=111,222
有没有办法在改造中做后者?
您可以尝试使用 Retrofit 的 @Url
注释来生成所需的 URL。
在您的服务接口文件中对您的 API 方法进行更改,
public interface YourServiceInterface {
@GET() // DO NOT pass any arguments here
Call<YourResponseObject> foo(@Url String url); // use @Url annotation here
}
在您的 Activity 或片段中。
String url = BASE_URL + "/endpoint?GTIN=111,222"; // https://example.com/endpoint?GTIN=111,222
YourServiceInterface api = ....;
Call<YourResponseObject> call = api.foo(url);
call.enqueue(/* implementation */);