- 原网址 https://www.jianshu.com/p/f57b7cdb1c99
- 在gradle文件中引用retrofit
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:retrofit-converters:2.3.0'
compile 'com.squareup.retrofit2:retrofit-adapters:2.3.0'
如果需要使用更多扩展功能,比如gson转换,rxjava适配等,可以视自己需要继续添加引用
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
/// http://120.27.23.105/product/getProducts?pscid=39&page=1 // @GET("product/getProducts") 是拼接的接口的 参数 ; type类型只能是接口的最后一个参数 // @QueryMap Map<String, String> map 是要拼接的 请求参数 pscid=39&page=1 // 注意::Base URL: 以"/"结尾 @Url:不要以"/"开头
.baseUrl("http://120.27.23.105/product/")
@GET("{type}?") Call<BizEntity> getBizInfo(@Path("type")
String type, @QueryMap Map<String, String> map)
关闭 接口
@Override protected void onDestroy() { super.onDestroy(); if (getProducts!=null){ getProducts.cancel(); getProducts=null; } }
// 全选与反选 public void getQuan() { priceCount=0; if (data!=null){ Observable.fromArray(data) .flatMap(new Function<List<MyData.DataBean>, ObservableSource<?>>() { @Override public ObservableSource<?> apply(@NonNull List<MyData.DataBean> dataBeen) throws Exception { return Observable.fromIterable(dataBeen); } }) .flatMap(new Function<Object, ObservableSource<?>>() { @Override public ObservableSource<?> apply(@NonNull Object o) throws Exception { return Observable.fromIterable(((MyData.DataBean)o).getList()); } }) .flatMap(new Function<Object, ObservableSource<?>>() { @Override public ObservableSource<?> apply(@NonNull Object o) throws Exception { Map<String, String> map = CommonParamsInterceptor.map; map.clear(); String s = quan.isChecked() ? "1" : "0"; String pa=quanPath+"&sellerid="+String.valueOf(((MyData.DataBean.ListBean)o).getSellerid())+"&pid="+String.valueOf(((MyData.DataBean.ListBean)o).getPid())+"&selected="+s; return MyRetrofit.getquan(pa); } }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new MyObserve(){ @Override protected void onMyComplete() { createPresenter().onGeyData(path); } @Override protected void onMyNext(Object o) { } }); } }