rtrofit @get @path 用注解@get("") 请求数据
来源:互联网 发布:淘宝美工面试被难倒 编辑:程序博客网 时间:2024/06/10 23:35
添加权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission><application android:name=".IapplicationInterface.IApplication"
package com.example.gq.workspace1.IapplicationInterface;import android.app.Application;import com.example.gq.workspace1.Bean;import com.example.gq.workspace1.R;import retrofit2.Call;import retrofit2.Callback;import retrofit2.Response;import retrofit2.Retrofit;import retrofit2.converter.gson.GsonConverterFactory;/** * Created by gq on 2017/12/3. */ //初始化public class IApplication extends Application { public static isGetDatabase getDatabase; @Override public void onCreate() { super.onCreate(); // 创建一个建造者 Retrofit retrofit=new Retrofit.Builder() .baseUrl("http://gank.io") .addConverterFactory(GsonConverterFactory.create()) //需要一个工厂来变成bean .build(); //跟路径接口有关系 getDatabase = retrofit.create(isGetDatabase.class); //getDatabase 可以调用那个方法 传参数进去 Call<Bean> call = getDatabase.getshuju(10, 1); call.enqueue(new Callback<Bean>() { @Override public void onResponse(Call<Bean> call, Response<Bean> response) { Bean bean = response.body(); System.out.println(Thread.currentThread().getName()); //看她走的哪个线程 } @Override public void onFailure(Call<Bean> call, Throwable t) { } }); }}
还有一个接口 请求得数据的接口
package com.example.gq.workspace1.IapplicationInterface;import com.example.gq.workspace1.Bean;import retrofit2.Call;import retrofit2.http.GET;import retrofit2.http.Path;/** * Created by gq on 2017/12/3. */public interface isGetDatabase { //写路径 @GET("/api/data/Android/{num1}/{num2}") Call<Bean> getshuju(@Path("num1") int key1,@Path("num2") int key) ; //用代替的话}
阅读全文
0 0
- rtrofit @get @path 用注解@get("") 请求数据
- Get同步请求数据
- 数据请求get post
- GET数据请求
- HttpUrlconnection get请求数据
- android get请求数据
- HttpClient --get 请求数据
- ajax post&get 请求数据
- get和post请求数据
- curl get post 请求数据
- iOS 数据请求 get、post
- get/post 数据请求方式
- HttpUrlConnection Get请求网络数据
- get请求数据(图片)
- Okhttp get异步请求数据
- get请求
- Get请求
- get请求
- EventBus进入Activity页面给Fragment传值,并弹出提示
- hdoj-1280前m大的数
- 插入排序和选择排序
- Mycat——由来
- 高精度加法
- rtrofit @get @path 用注解@get("") 请求数据
- Panel以及Label的设置
- 【技术重温】html之重点(二)
- SpringBoot与Thymeleaf实现国际化
- 带有首尾的可反转链表(LinkedList)的java实现
- Codeforces #339 D. Jon and Orbs(概率dp)
- Div+CSS网页设计(HTML5)
- mybatis中一级缓存和二级缓存的简单介绍
- ROS起步