@Path 作为可选参数?
@Path as optional param?
在我的 android 项目中,我使用 Retrofit:
@POST("/correspondents/{correspondent_id}")
fun updateCorrespondent(@Path("correspondent_id") correspondentId: String, @Body body: JsonElement): Call<Void>
所以我这样从客户那里打电话:
fun updateCorrespondent(correspondent: Correspondent, callback: Callback<Void>) {
val call = myRestClient.updateCorrespondent(correspondent.id, correspondent.toUpdateJson())
call.enqueue(callback)
}
很好,工作正常。
但我需要@Path("correspondent_id")
可选。
我需要像这样从客户端调用:
fun updateCorrespondent(correspondent: Correspondent, callback: Callback<Void>) {
val call = tangoRestClient.updateCorrespondent(correspondent.toUpdateJson())
call.enqueue(callback)
}
可能吗?
现在我使用两种不同的方法:
@POST("/correspondents/{correspondent_id}")
fun updateCorrespondent(@Path("correspondent_id") correspondentId: String, @Body body: JsonElement): Call<Void>
@POST("/correspondents/create")
fun createCorrespondent(@Body body: JsonElement): Call<Void>
是否可以仅使用一种可选的方法@Path
?
@POST("/correspondents/{correspondent_id}") fun updateCorrespondent(@Path("correspondent_id") correspondentId: String?="create", @Body body: JsonElement): Call<Void>
当您不需要通讯员 ID 时,请致电 luke
mtRestClient.updateCorrespondent(body = correspondent.toUpdateJson())
在我的 android 项目中,我使用 Retrofit:
@POST("/correspondents/{correspondent_id}")
fun updateCorrespondent(@Path("correspondent_id") correspondentId: String, @Body body: JsonElement): Call<Void>
所以我这样从客户那里打电话:
fun updateCorrespondent(correspondent: Correspondent, callback: Callback<Void>) {
val call = myRestClient.updateCorrespondent(correspondent.id, correspondent.toUpdateJson())
call.enqueue(callback)
}
很好,工作正常。
但我需要@Path("correspondent_id")
可选。
我需要像这样从客户端调用:
fun updateCorrespondent(correspondent: Correspondent, callback: Callback<Void>) {
val call = tangoRestClient.updateCorrespondent(correspondent.toUpdateJson())
call.enqueue(callback)
}
可能吗?
现在我使用两种不同的方法:
@POST("/correspondents/{correspondent_id}")
fun updateCorrespondent(@Path("correspondent_id") correspondentId: String, @Body body: JsonElement): Call<Void>
@POST("/correspondents/create")
fun createCorrespondent(@Body body: JsonElement): Call<Void>
是否可以仅使用一种可选的方法@Path
?
@POST("/correspondents/{correspondent_id}") fun updateCorrespondent(@Path("correspondent_id") correspondentId: String?="create", @Body body: JsonElement): Call<Void>
当您不需要通讯员 ID 时,请致电 luke
mtRestClient.updateCorrespondent(body = correspondent.toUpdateJson())