我目前正在使用改装1.9我在使用它时遇到很多问题,比如我得到改装管道损坏错误和许多东西所以基本上现在我打算从1.9迁移到2.0但我很困惑并且完全沮丧尝试不同的步骤过来吧。如果你能帮助我克服它,我将非常感谢你们。我有我的改装1.9代码发布和获取请求下面。请帮我改变我的代码
1>这是我目前唯一使用的1个改进依赖项 编译'com.squareup.retrofit:retrofit:1.9.0' 那么我对依赖项进行了哪些更改
2>我的post和get
的改装界面 @POST("/trinkingu/operations.php")
void createNewSeekerProfile( @Query("module") String module,
@Query("action") String action,
@Body SeekerProfileModel body, Callback<Response> callback);
@GET("/synkku/services.php")
void getAlljobPosts(@Query("module") String module,
@Query("action") String action,
@Query("key") String key,
@Query("value") String value, Callback<ArrayList<JobsModel>> response);
3&gt; My Retrofit Helper类
public void addNewSeekerProfile(String module,String action,SeekerProfileModel seekerProfileModel) {
//Here we will handle the http request to insert user to mysql db
//Creating a RestAdapter
System.out.println("##coming here");
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Allconstants.MAIN_URL) //Setting the Root URL
.build(); //Finally building the adapter
//Creating object for our interface
RetroApiInterface api = adapter.create(RetroApiInterface.class);
//Defining the method insertuser of our interface
api.createNewSeekerProfile(
module,
action,
seekerProfileModel,
new Callback<Response>() {
@Override
public void success(Response response, Response response2) {
TypedInput body = response.getBody();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(body.in()));
StringBuilder out = new StringBuilder();
String newLine = System.getProperty("line.separator");
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
out.append(newLine);
}
// Prints the correct String representation of body.
System.out.println(out);
Toast.makeText(mContext,"result"+out,Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void failure(RetrofitError error) {
Toast.makeText(mContext,"error"+error.toString(),Toast.LENGTH_LONG).show();
error.printStackTrace();
}
}
);
}
这是得到
public void getAllMyPostedJobs(String inputKey, String inputValue) {
//While the app fetched data we are displaying a progress dialog
//Creating a rest adapter
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Allconstants.MAIN_URL)
.build();
//Creating an object of our api interface
RetroApiInterface api = adapter.create(RetroApiInterface.class);
api.getAlljobPosts(Allconstants.JOBS, Allconstants.ACTION_GET_ALL_MY_POSTEDJOBS, inputKey, inputValue, new Callback<ArrayList<JobsModel>>() {
@Override
public void success(ArrayList<JobsModel> jobsModels, Response response) {
if (mResultCallback != null)
mResultCallback.notifySuccess(jobsModels, response);
System.out.println("###successfull ");
}
@Override
public void failure(RetrofitError error) {
if (mResultCallback != null)
mResultCallback.notifyError(error);
}
});
}
请帮助我进行更改,以便迁移到2.0 你的帮助将更加受到赞赏 在此先感谢:)
答案 0 :(得分:0)
编译:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
创建界面:
public interface ItemAPI {
@GET("/synkku/services.php")
call<JobsModel> getAlljobPosts(@Query("module") String module,
@Query("action") String action,
@Query("key") String key,
@Query("value") String value);
}
创建课程:
public class Apiclient {
public static final String BASE_URL = "YOUR BASE_URL";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
现在,在您的活动中:
ItemAPI itemAPI = Apiclient.getClient().create(ItemAPI.class);
Call<JobsModel> call=itemAPI.getAlljobPosts(Allconstants.JOBS, Allconstants.ACTION_GET_ALL_MY_POSTEDJOBS, inputKey, inputValue);
call.enqueue(new Callback<JobsModel>() {
@Override
public void onResponse(Call<JobsModel> call, Response<JobsModel> response) {
try {
HERE YOU CAN GET JoBSModel VIA RESPONSE.BODY."your model method name"
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onFailedAfterRetry(Throwable t) {
}
});
答案 1 :(得分:0)
public class JobsModel实现了Serializable {
@SerializedName("_id")
private String _id = null;
@SerializedName("posted_by")
private String userId = null;
@SerializedName("company_name")
private String companyName = null;
@SerializedName("position")
private String position = null;
@SerializedName("eligiblity")
private String eligiblity = null;
@SerializedName("experience")
private String experience = null;
@SerializedName("interview_from_date")
private String interviewFromDate = null;
@SerializedName("interview_to_date")
private String interviewToDate = null;
@SerializedName("interview_frm_timing")
private String interviewTimeFrom = null;
@SerializedName("interview_to_timing")
private String interviewTimeTo = null;
@SerializedName("describtion")
private String desc = null;
@SerializedName("skills")
private String skills = null;
@SerializedName("interview_location")
private String interviewLocation = null;
@SerializedName("interview_lat")
private float lat;
@SerializedName("interview_lon")
private float lon;
@SerializedName("contact_person")
private String contactPerson = null;
@SerializedName("contact_phone")
private String contactPhone = null;
@SerializedName("contact_email")
private String contactMail = null;
@SerializedName("total_vocancies")
private int totalVocancies;
@SerializedName("posted_on")
private String postedOn;
@SerializedName("currently_active")
private String currently_active;
@SerializedName("sal_pckg")
private String salPckg;
public JobsModel(String _id, String userId, String companyName, String position, String eligiblity,
String experience, String interviewFromDate, String interviewToDate, String interviewTimeFrom, String interviewTimeTo,
String desc, String skills, String interviewLocation,
String contactPerson, String contactPhone, String contactMail, int totalVocancies, String postedOn, String isActive,String salPckg) {
this._id=_id;
this.userId = userId;
this.companyName = companyName;
this.position = position;
this.eligiblity = eligiblity;
this.experience = experience;
this.interviewFromDate = interviewFromDate;
this.interviewToDate = interviewToDate;
this.interviewTimeFrom = interviewTimeFrom;
this.interviewTimeTo = interviewTimeTo;
this.desc = desc;
this.skills = skills;
this.interviewLocation = interviewLocation;
this.contactPerson = contactPerson;
this.contactPhone = contactPhone;
this.contactMail = contactMail;
this.totalVocancies = totalVocancies;
this.postedOn=postedOn;
this.currently_active =isActive;
this.salPckg=salPckg;
}
public String getSalPckg() {
return salPckg;
}
public void setSalPckg(String salPckg) {
this.salPckg = salPckg;
}
public String get_id() {
return _id;
}
public void set_id(String _id) {
this._id = _id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getEligiblity() {
return eligiblity;
}
public void setEligiblity(String eligiblity) {
this.eligiblity = eligiblity;
}
public String getExperience() {
return experience;
}
public void setExperience(String experience) {
this.experience = experience;
}
public String getInterviewFromDate() {
return interviewFromDate;
}
public void setInterviewFromDate(String interviewFromDate) {
this.interviewFromDate = interviewFromDate;
}
public String getInterviewToDate() {
return interviewToDate;
}
public void setInterviewToDate(String interviewToDate) {
this.interviewToDate = interviewToDate;
}
public String getInterviewTimeFrom() {
return interviewTimeFrom;
}
public void setInterviewTimeFrom(String interviewTimeFrom) {
this.interviewTimeFrom = interviewTimeFrom;
}
public String getInterviewTimeTo() {
return interviewTimeTo;
}
public void setInterviewTimeTo(String interviewTimeTo) {
this.interviewTimeTo = interviewTimeTo;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getSkills() {
return skills;
}
public void setSkills(String skills) {
this.skills = skills;
}
public String getInterviewLocation() {
return interviewLocation;
}
public void setInterviewLocation(String interviewLocation) {
this.interviewLocation = interviewLocation;
}
public float getLat() {
return lat;
}
public void setLat(float lat) {
this.lat = lat;
}
public float getLon() {
return lon;
}
public void setLon(float lon) {
this.lon = lon;
}
public String getContactPerson() {
return contactPerson;
}
public void setContactPerson(String contactPerson) {
this.contactPerson = contactPerson;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}
public String getContactMail() {
return contactMail;
}
public void setContactMail(String contactMail) {
this.contactMail = contactMail;
}
public int getTotalVocancies() {
return totalVocancies;
}
public void setTotalVocancies(int totalVocancies) {
this.totalVocancies = totalVocancies;
}
public String getPostedOn() {
return postedOn;
}
public void setPostedOn(String postedOn) {
this.postedOn = postedOn;
}
public String getCurrently_active() {
return currently_active;
}
public void setCurrently_active(String currently_active) {
this.currently_active = currently_active;
}
}