将后端的数据传到安卓端
This commit is contained in:
parent
e7448667ce
commit
db95cdb811
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface AdvertisementApi {
|
||||
@FormUrlEncoded
|
||||
@POST("advertise")
|
||||
@POST("advertise/getAdvertiseList")
|
||||
Call<Advertisement> advertise (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface ChatApi {
|
||||
@FormUrlEncoded
|
||||
@POST("chat")
|
||||
@POST("chat/getChatList")
|
||||
Call<Chat> chat (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface Class2Api {
|
||||
@FormUrlEncoded
|
||||
@POST("Class2")
|
||||
@POST("Class2/getClass2List")
|
||||
Call<Class2_home> class2 (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface ClassApi {
|
||||
@FormUrlEncoded
|
||||
@POST("Class")
|
||||
@POST("Class/getClassList")
|
||||
Call<Class_home> class1 (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface Expert1Api {
|
||||
@FormUrlEncoded
|
||||
@POST("expert1")
|
||||
@POST("expert1/getExpert1List")
|
||||
Call<Expert1> people (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface Expert2Api {
|
||||
@FormUrlEncoded
|
||||
@POST("expert2")
|
||||
@POST("expert2/getExpert2List")
|
||||
Call<Expert2> people2 (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface Goods1Api {
|
||||
@FormUrlEncoded
|
||||
@POST("goods1")
|
||||
@POST("goods1/getGoods1List")
|
||||
Call<Goods1> good (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface Goods2Api {
|
||||
@FormUrlEncoded
|
||||
@POST("goods2")
|
||||
@POST("goods1/getGoods1List")
|
||||
Call<Goods2> good (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.example.liyueling_final;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoginUser {
|
||||
|
||||
@SerializedName("msg")
|
||||
public String msg;
|
||||
@SerializedName("code")
|
||||
public Integer code;
|
||||
@SerializedName("data")
|
||||
public List<DataDTO> data;
|
||||
|
||||
public static class DataDTO {
|
||||
@SerializedName("id")
|
||||
public Integer id;
|
||||
@SerializedName("username")
|
||||
public String username;
|
||||
@SerializedName("password")
|
||||
public String password;
|
||||
@SerializedName("phone")
|
||||
public String phone;
|
||||
@SerializedName("userImg")
|
||||
public String userImg;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.example.liyueling_final;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface LoginUserApi {
|
||||
@FormUrlEncoded
|
||||
@POST("login")
|
||||
Call<LoginUser> login(@Field("id") Integer id);
|
||||
}
|
|
@ -81,13 +81,14 @@ public class MainexpertFragment extends Fragment {
|
|||
recyclerView3.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
|
||||
Expert1Api expert1Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Expert1Api.class);
|
||||
Expert2Api expert2Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Expert2Api.class);
|
||||
Expert1Api expert1Api = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(Expert1Api.class);
|
||||
Expert2Api expert2Api = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(Expert2Api.class);
|
||||
Call<Expert1> call = expert1Api.people(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call.enqueue(new Callback<Expert1>() {
|
||||
@Override
|
||||
public void onResponse(Call<Expert1> call, Response<Expert1> response) {
|
||||
Log.i("ui123456", "onFailure: ");
|
||||
Expert1 expert1 = response.body();
|
||||
for (Expert1.DataDTO data : expert1.data) {
|
||||
if (data.id < 7) {
|
||||
|
@ -99,9 +100,10 @@ public class MainexpertFragment extends Fragment {
|
|||
myAdpater.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Expert1> call, Throwable t) {
|
||||
|
||||
Log.i("data", "Request failed: " + t.getMessage());
|
||||
}
|
||||
});
|
||||
recyclerView = view.findViewById(R.id.recyclerview1);
|
||||
|
|
|
@ -66,8 +66,8 @@ public class MaingoodFragment extends Fragment {
|
|||
recyclerView3.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
|
||||
Goods1Api goods1Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Goods1Api.class);
|
||||
Goods2Api goods2Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Goods2Api.class);
|
||||
Goods1Api goods1Api = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(Goods1Api.class);
|
||||
Goods2Api goods2Api = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(Goods2Api.class);
|
||||
Call<Goods1> call = goods1Api.good(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call.enqueue(new Callback<Goods1>() {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class MainhomeFragment extends Fragment {
|
|||
recyclerView4.setAdapter(myAdpater2);
|
||||
recyclerView4.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
// Inflate the layout for this fragment
|
||||
ClassApi classApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(ClassApi.class);
|
||||
ClassApi classApi = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(ClassApi.class);
|
||||
Call<Class_home> call = classApi.class1(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call.enqueue(new Callback<Class_home>() {
|
||||
|
@ -125,7 +125,7 @@ public class MainhomeFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
Class2Api class2Api = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(Class2Api.class);
|
||||
Class2Api class2Api = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(Class2Api.class);
|
||||
Call<Class2_home> call2 = class2Api.class2(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call2.enqueue(new Callback<Class2_home>() {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MainmajorFragment extends Fragment {
|
|||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_mainmajor, container, false);
|
||||
|
||||
PeopleApi peopleApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(PeopleApi.class);
|
||||
PeopleApi peopleApi = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(PeopleApi.class);
|
||||
Call<People> call = peopleApi.Introduce(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call.enqueue(new Callback<People>() {
|
||||
|
@ -59,7 +59,7 @@ public class MainmajorFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
AdvertisementApi advertisementApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(AdvertisementApi.class);
|
||||
AdvertisementApi advertisementApi = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(AdvertisementApi.class);
|
||||
Call<Advertisement> call2 = advertisementApi.advertise(0);
|
||||
Log.i("123456", "onFailure: ");
|
||||
call2.enqueue(new Callback<Advertisement>() {
|
||||
|
|
|
@ -7,6 +7,6 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface PeopleApi {
|
||||
@FormUrlEncoded
|
||||
@POST("people")
|
||||
@POST("people/getPeopleList")
|
||||
Call<People> Introduce (@Field("id") Integer id);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class Study_pinglun extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
UserApi userApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(UserApi.class);
|
||||
UserApi userApi = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(UserApi.class);
|
||||
for(int i=1;i<8;i++){
|
||||
Call<User> call = userApi.Comment(i);
|
||||
call.enqueue(new Callback<User>() {
|
||||
|
|
|
@ -7,7 +7,7 @@ import retrofit2.http.POST;
|
|||
|
||||
public interface UserApi {
|
||||
@FormUrlEncoded
|
||||
@POST("comment")
|
||||
@POST("comment/getCommentList")
|
||||
Call<User> Comment (@Field("id") Integer id);
|
||||
|
||||
|
||||
|
|
|
@ -83,8 +83,8 @@ public class UserFragment extends Fragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setMessage("Are you sure you want to logout?")
|
||||
.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
|
||||
builder.setMessage("你确定你要退出吗?")
|
||||
.setPositiveButton("退出", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// 执行退出登录操作
|
||||
Intent intent = new Intent(getActivity(), LoginMainActivity.class);
|
||||
|
@ -92,7 +92,7 @@ public class UserFragment extends Fragment {
|
|||
getActivity().finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// 取消操作,关闭对话框
|
||||
dialog.dismiss();
|
||||
|
@ -163,7 +163,7 @@ public class UserFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
ChatApi chatApi = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(ChatApi.class);
|
||||
ChatApi chatApi = RetrofitUtils.getRetrofit("http://10.0.2.2:8081/").create(ChatApi.class);
|
||||
Call<Chat> call = chatApi.chat(0);
|
||||
call.enqueue(new Callback<Chat>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue