没有“&"号的改进查询注释 [英] Retrofit Query Annotation Without Ampersand

查看:131
本文介绍了没有“&"号的改进查询注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Retrofit 2.0对移动后端进行API调用.在我的API调用中,我必须对此URL进行必要的调用

I am trying to make an API call to a mobile backend with Retrofit 2.0. In my API call, i have to make necessary call to this URL

https ://api.backendless.com/v1/data/Users?where = followings.objectId =%270B3BA7F9-260F-B378-FF9A-3C2448B8A700%27

要在翻新中形成此URL,我一直在使用以下界面

To form this URL in Retrofit i have been using below interface

@GET("Users?where=")
Call<List<User>> getFollowers(@Query("followings.objectId") String objectId);

此接口调用在查询参数前放置一个&符号,并生成如下所示的URL

This interface call puts an ampersand before the query parameters and generates a URL like below

https://api.backendless.com/v1/data/Users?where=&followings.objectId=%270B3BA7F9-260F-B378-FF9A-3C2448B8A700%27

我试图通过路径注释来克服这个问题,但是我不断收到"URL查询字符串不能包含replace块.对于使用@Query的动态查询参数"错误.

I tried to overcome this with Path annotation but i keep getting "URL query string must not have replace block. For dynamic query parameters using @Query" error.

API要求使用"where =子句来按设计进行过滤.我无权更改.我想要的是以某种方式告诉Retrofit,不要在查询参数或此问题的任何变通方法前加上&"号.

API that i am trying to connect requires a "where=" clause for filtering by design. I have no permission to change that. What i want is somehow tell Retrofit not to put an ampersand sign before the query parameter or any workarounds for this issue.

感谢您的帮助.

推荐答案

对于那些寻求类似答案的人,我想出了以下解决方案

For those who seek for similar answers, I came up with below solution

我用@Url声明了我的界面

I declared my interface with @Url

@GET
Call<List<User>> getFollowers(@Url String objectId);

并生成相关的URL部分作为扩展方法

and generated related URL part as an extension method

public String toFollowerRequest(){
    return RestGlobals.BASE_URL + "Users?where=followings.objectId=%27" + objectId + "%27";
}

这篇关于没有“&"号的改进查询注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆