如何执行删除请求而不返回类型或回调?(改造)
I need perform a DELETE request using Retrofit. So, my code snippet of the interface looks like this:
我需要使用Retrofit执行删除请求。因此,我的接口代码片段如下:
@DELETE("/api/item/{id}")
void deleteItem(@Path("id") int itemId);
But I get the error:
但我得到了一个错误:
java.lang.IllegalArgumentException: ApiItem.deleteItem: Must have either a return type or Callback as last argument.
. lang。IllegalArgumentException: ApiItem.deleteItem:必须有返回类型或回调作为最后一个参数。
However, according to the rules of Rest API, I shouldn't receive any response to DELETE request. How should I specify it in the interface?
但是,根据Rest API的规则,我不应该收到任何删除请求的响应。如何在接口中指定它?
Thanks.
谢谢。
2 个解决方案
#1
23
You have to add Callback as last argument in request method if you want to have void method. You can useCallback<Response>
.
如果想要使用void方法,就必须在request方法中添加回调作为最后一个参数。你可以useCallback响应> <。
You have to change this:
你必须改变这一点:
@DELETE("/api/item/{id}")
void deleteItem(@Path("id") int itemId);
to :
:
@DELETE("/api/item/{id}")
void deleteItem(@Path("id") int itemId, Callback<Response> callback);
Or you can return just Response
或者你可以只返回响应
@DELETE("/api/item/{id}")
Response deleteItem(@Path("id") int itemId);
更多相关文章
- 在网页程序或Java程序中调用接口实现短信猫收发短信的解决方案
- Java 8 新特性-菜鸟教程 (3) -Java 8 函数式接口
- java socket参数详解:TcpNoDelay
- 在spring 中如何注入map,set,list,property等参数
- 如何将动态参数传递给jquery函数
- 使用字符串参数调用AndroidJni静态方法。
- Java开发水吧点饮品系统(顶层父类对象做接口参数)
- java返回值是list的时候获取list的参数类型
- Java反射---getGenericSuperclass和ParameterizedType参数化类型