2014-09-29 32 views

回答

15

retrofit documentation

對於複雜的查詢參數的組合一個Map可以使用。

@GET("/group/{id}/users") 
List<User> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options); 

我想這會讓你想要達到的目標。

+0

@QueryMap不允許包含查詢參數沒有任何價值。從文檔:「值是URL編碼,null不會在URL中包含查詢參數」 – 2014-09-30 09:33:32

+1

空字符串怎麼樣? – WojciechKo 2014-09-30 17:10:18

+0

它會生成具有相等符號的網址: https://myserver.com/setservices?service[100]=&service[10000]=&service[10]= 但服務器很好理解。 – 2014-09-30 17:38:43

5

我發現解決方法如何做到這一點。

@GET("/setservices{services_query}") 
ServicesSetResponse setServices(@EncodedPath("services_query") String servicesQuery); 

然後:

getService().setServices("?param1=val1&param2=val2" + "&services[10]&services[100000]&services[1000000]")