在 Kotlin 改造中调用函数作为发送参数的问题
Problem in calling function as a send parameter in Kotlin retrofit
我遇到的问题是,我不知道如何在演示者和视图中的以下函数中调用查询参数(id) 类。架构是 mvp。
我的APIURL是::http://soanitravel.com/api/bookingdetail?id=2
我的 api 声明::
const val BASE_URL = "http://soanitravel.com/api/"
const val BOOKINGDETAILS = "bookingdetail/{id}"
我试过这样获取 api 数据::
//GetFunction
@GET(Apiurl.BOOKINGDETAILS)
fun postBookingDetails(@Header("Authorization") token: BookingDetailsResponse, @Path("id") id: Int?): Observable<BookingDetailsResponse><br>
//Model class
fun getBookingDetails(info: BookingDetailsResponse,id: Int): Observable<BookingDetailsResponse> {
return webservice.postBookingDetails(info, id)
}
//presenter class
private fun DashboardRequest() {
compositeDisposable.add(
bookingDetailsModel.getBookingDetails(bookingDetailsView.getBookingDetailsRequest()) /// here red errors says id to put in getBookingDetailsRequest())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(this::dashboardSuccess, this::dashboardError)
)
}
//View class
fun getBookingDetailsRequest(): BookingDetailsResponse {
return BookingDetailsResponse()
}
Retrofit 支持@Path 和@Query 参数。这里需要使用@Query。
@GET(Apiurl.BOOKINGDETAILS)
fun postBookingDetails(@Header("Authorization") token: BookingDetailsResponse,
@Query("id") id: Int?): Observable<BookingDetailsResponse>
为了更好的理解
URI/Path参数
GET bookingdetail/2
查询参数。
GET bookingdetail?id=2
我遇到的问题是,我不知道如何在演示者和视图中的以下函数中调用查询参数(id) 类。架构是 mvp。
我的APIURL是::http://soanitravel.com/api/bookingdetail?id=2
我的 api 声明::
const val BASE_URL = "http://soanitravel.com/api/"
const val BOOKINGDETAILS = "bookingdetail/{id}"
我试过这样获取 api 数据::
//GetFunction
@GET(Apiurl.BOOKINGDETAILS)
fun postBookingDetails(@Header("Authorization") token: BookingDetailsResponse, @Path("id") id: Int?): Observable<BookingDetailsResponse><br>
//Model class
fun getBookingDetails(info: BookingDetailsResponse,id: Int): Observable<BookingDetailsResponse> {
return webservice.postBookingDetails(info, id)
}
//presenter class
private fun DashboardRequest() {
compositeDisposable.add(
bookingDetailsModel.getBookingDetails(bookingDetailsView.getBookingDetailsRequest()) /// here red errors says id to put in getBookingDetailsRequest())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(this::dashboardSuccess, this::dashboardError)
)
}
//View class
fun getBookingDetailsRequest(): BookingDetailsResponse {
return BookingDetailsResponse()
}
Retrofit 支持@Path 和@Query 参数。这里需要使用@Query。
@GET(Apiurl.BOOKINGDETAILS)
fun postBookingDetails(@Header("Authorization") token: BookingDetailsResponse,
@Query("id") id: Int?): Observable<BookingDetailsResponse>
为了更好的理解
URI/Path参数
GET bookingdetail/2
查询参数。
GET bookingdetail?id=2