我可以将参数发送到 kotlin 中的接口吗?

Can I send parameter to the Interface in kotlin?

我在改进 API 请求中使用 @Get 接口,而不是为每个调用创建 @Get 函数我想将参数发送到 @Get 函数,我该怎么做?像下面的例子

接口 SomeApiService(catId:字符串){

@GET(EN_PRODUCTLIST+catId)
fun getProductByCatId():
        Deferred<SomeProduct>

}

对象 SomeApi { val retrofitService : SomeApiService by lazy { retrofit.create(SomeApiService::class.java) } }

当我调用 SomeApi(catId).getProductByCatId() 时,它将 return 特定产品的 catId。 怎么做?

你必须这样做

@GET("EN_PRODUCTLIST{catId}")
fun getProductByCatId(@Path(catId) catId:String):Deferred<SomeProduct>

@Path 将参数放入请求的url路径中。

请再次阅读文档https://square.github.io/retrofit/