【发布时间】:2018-10-07 16:27:59
【问题描述】:
其实我想通过retrofit2 api从Mysql数据库中获取数据。我正在根据类别 1 或 2 等类别获取数据,但我收到错误 @Field parameters can only be used with form encoding. (parameter #1)for method APIService.savePost
这是我的接口代码:
public interface APIService {
@GET("fetchtext.php")
Call<List<DataStored>> savePost(@Field("catId") String catId);
@GET("testing.php")
Call<List<DataStored>> searchcategory(@Field("catId") String catId,
@Field("SubCatego") String SubCatego);
}
这是我的 ApiUtils 类:
public class ApiUtils {
private ApiUtils() {}
public static final String BASE_URL = "http://192.168.9.10/";
public static APIService getAPIService() {
return RetrofitClient.getClient(BASE_URL).create(APIService.class);
}
}
RetrofitClient 类:
public class RetrofitClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}}
我正在创建调用 RetroApi 的片段中的代码:
mAPIService = ApiUtils.getAPIService();
mAPIService.savePost(category).enqueue(new Callback<List<DataStored>>() {
@Override
public void onResponse(Call<List<DataStored>> call, Response<List<DataStored>> response) {
dataStored= response.body();
myRecyclerAdapter.addItems(dataStored);
}
@Override
public void onFailure(Call<List<DataStored>> call, Throwable t) {
}
});
请告诉我如何将类别发送到数据库进行比较 数据库中可用的类别数据然后将数据转换为 Json 并在 android 中发送回以显示在 android 中的 RecyclerView 上。
【问题讨论】:
标签: php android api syntax-error retrofit2