This commit is contained in:
饶秋霖 2024-12-07 18:27:18 +08:00
parent 0166c8e20f
commit c660e0af0c
6 changed files with 145 additions and 1 deletions

View File

@ -4,11 +4,16 @@ import java.util.Map;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
public interface Api {
@POST("login")
Call<LoginResult> login(@Body Map<String,String> map);
@GET("/system/doctor/list")
Call<DoctorResult> doctorlist(@Header("Authorization")String token);
@GET("/system/doctor/list")
Call<DepartmentResult> departmentlist(@Header("Authorization")String token);
}

View File

@ -0,0 +1,23 @@
package com.hnucm.c202201020141;
import java.util.List;
public class DepartmentResult {
public Integer total;
public Integer code;
public String msg;
public List<RowsDTO> rows;
public static class RowsDTO {
public Object createBy;
public Object createTime;
public Object updateBy;
public Object updateTime;
public Object remark;
public Integer id;
public String department;
public String number;
public String picture;
}
}

View File

@ -0,0 +1,24 @@
package com.hnucm.c202201020141;
import java.util.List;
public class DoctorResult {
public Integer total;
public Integer code;
public String msg;
public List<RowsDTO> rows;
public static class RowsDTO {
public Object createBy;
public Object createTime;
public Object updateBy;
public Object updateTime;
public Object remark;
public Integer id;
public String doctor;
public String expert;
public String cost;
public String picture;
}
}

View File

@ -1,6 +1,8 @@
package com.hnucm.c202201020141;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -151,6 +153,29 @@ public class HomeActivity2 extends AppCompatActivity {
holder.Layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// http://10.138.6.102:8080/system/departments/list
SharedPreferences sharedPreferences= getSharedPreferences("data", Context.MODE_PRIVATE);
String token=sharedPreferences.getString("token","");
retrofit2.Call<DepartmentResult> departmentResultCall= RetrofitUtils.getRetrofit("http://10.138.6.102:8080/system/departments/list/")
.create(Api.class)
.departmentlist("Bearer "+token);
departmentResultCall.enqueue(new retrofit2.Callback<DepartmentResult>() {
@Override
public void onResponse(retrofit2.Call<DepartmentResult> call, retrofit2.Response<DepartmentResult> response) {
DepartmentResult departmentResult=response.body();
if (departmentResult.code==200){
}else{
}
}
@Override
public void onFailure(retrofit2.Call<DepartmentResult> call, Throwable t) {
}
});
Intent intent=new Intent(HomeActivity2.this, HomeActivity3.class);
startActivity(intent);
}

View File

@ -1,7 +1,9 @@
package com.hnucm.c202201020141;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@ -20,6 +22,11 @@ import com.youth.banner.indicator.CircleIndicator;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
public class HomeFragment extends Fragment {
@ -52,6 +59,29 @@ public class HomeFragment extends Fragment {
textView27.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sharedPreferences= requireContext().getSharedPreferences("data", Context.MODE_PRIVATE);
String token=sharedPreferences.getString("token","");
Call<DoctorResult> doctorResultCall= RetrofitUtils.getRetrofit("http://10.138.6.102:8080/system/doctor/list/")
.create(Api.class)
.doctorlist("Bearer "+token);
doctorResultCall.enqueue(new Callback<DoctorResult>() {
@Override
public void onResponse(Call<DoctorResult> call, Response<DoctorResult> response) {
DoctorResult doctorResult=response.body();
if (doctorResult.code==200){
}else{
}
}
@Override
public void onFailure(Call<DoctorResult> call, Throwable t) {
}
});
Intent intent=new Intent(getActivity(),HomeActivity2.class);
startActivity(intent);
}

View File

@ -0,0 +1,37 @@
package com.hnucm.c202201020141;
import android.util.Log;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitUtils {
public static Retrofit getRetrofit(String url) {
//日志显示级别
HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BODY;
//新建log拦截器
HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.d("RetrofitMessage","OkHttp====Message:"+message);
}
});
loggingInterceptor.setLevel(level);
//定制OkHttp
OkHttpClient.Builder httpClientBuilder = new OkHttpClient
.Builder();
//OkHttp进行添加拦截器loggingInterceptor
httpClientBuilder.addInterceptor(loggingInterceptor);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.client( httpClientBuilder.build())
.build();
return retrofit;
}
}