【发布时间】:2021-02-16 14:34:34
【问题描述】:
我在改造 API 请求中使用 @Get 接口,而不是为每个调用创建 @Get 函数,我想将参数发送到 @Get 函数,我该怎么做?像下面的例子
接口 SomeApiService(catId: String) {
@GET(EN_PRODUCTLIST+catId)
fun getProductByCatId():
Deferred<SomeProduct>
}
对象 SomeApi { val retrofitService : SomeApiService bylazy { retrofit.create(SomeApiService::class.java) } }
当我调用 SomeApi(catId).getProductByCatId() 时,它将通过 catId 返回该特定产品。 该怎么做?
【问题讨论】:
-
不,接口不是这样工作的
-
我如何从外部向@Get(productAtId) 发送请求?你知道我该怎么做吗?
-
为什么不在函数中发送?
-
它会在@Get 中起作用吗?
-
你的意思是像:@GET(EN_PRODUCTLIST) fun getProductByCatId(catId: String): Deferred
标签: android api kotlin interface retrofit