gpt4 book ai didi

android - Retrofit2 GET批注动态网址

转载 作者:行者123 更新时间:2023-12-02 13:36:02 25 4
gpt4 key购买 nike

我需要帮助,因为我有使用Java语言进行Android开发的经验,并且在Kotlin有一点经验。我被困在使用改造库并与服务器通信的代码上,我想从类的构造函数中将变量添加到改造的GET注释中,但我做不到,所以请帮忙我在这。

我将在下面显示我的代码:

class UniSearchModel(private val country:String) {

interface UniServices {
@GET("get_uni_of_country.php?country=$country")
fun viewEvent(): Call<List<UniResponse>>

}
}

现在,我要做的是将构造函数中的国家/地区变量添加到此批注中,以使其成为动态网址,但它给了我两个错误:
  • 批注参数必须是编译时常量。
  • Unresolved reference :国家
  • 最佳答案

    您必须添加一个特殊的@Query注释。

    因此,您应该这样做:

    class UniSearchModel(private val country:String) {

    interface UniServices {

    @GET("get_uni_of_country.php")

    fun viewEvent(@Query("country") country: String): Call<List<UniResponse>>

    }
    }

    关于android - Retrofit2 GET批注动态网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57084667/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com