改造@DELETE

时间:2017-10-30 11:47:05

标签: android retrofit2

为什么我不能将@DELETE@Url参数一起使用

@DELETE
Call<ServerResponse> deleteAbsence(@Path("id") int absenceId , @Url String url);

Url passed ="././deleteAbsence/{id}"

堆栈跟踪

 java.lang.IllegalArgumentException: @Path can only be used with relative url on @DELETE (parameter #2)
                                                                        for method WebApiInterface.deleteAbsence
                                                                        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:752)
                                                                        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:743)
                                                                        at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:761)
                                                                        at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:393)
                                                                        at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:336)
                                                                        at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:204)
                                                                        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
                                                                        at retrofit2.Retrofit$1.invoke(Retrofit.java:147)

2 个答案:

答案 0 :(得分:3)

尝试使用@Query("id").

@DELETE
Call<ServerResponse> deleteAbsence(@Query("id") int absenceId , @Url String url);

答案 1 :(得分:0)

带有@Path注释的参数会替换@DELETE注释中提供的路径中的提供值。

如果您的任何方法参数都使用@Path注释进行注释,则必须在@DELETE注释中提供相对路径作为参数。

将相对路径设置为@DELETE注释中的参数,而不是方法。

@DELETE("././deleteAbsence/{id}")
Call <ServerResponse> deleteAbsence(@Path("id") int absenceId);