private Retrofit retrofit;
private static RetrofitUtils retrofitUtils;
private RetrofitUtils() {
doretrofit();
}
//单例模式
public static RetrofitUtils getInstense() {
if (retrofitUtils == null) {
synchronized (RetrofitUtils.class) {
if (retrofitUtils == null) {
retrofitUtils = new RetrofitUtils();
}
}
}
return retrofitUtils;
}
//Retrofit+Rxjava
private void doretrofit() {
//创建构造模式
retrofit = new Retrofit.Builder()
.baseUrl("http://mobile.bwstudent.com/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
public <T> T create(Class<T> service) {
return retrofit.create(service);
}
Retrofit+Rxjava封装单例
最新推荐文章于 2022-06-04 09:56:29 发布