supengchao / supengchao.github.io

个人博客代码仓库
http://www.supengchao.com
Other
1 stars 0 forks source link

retrofit学习 #1

Open supengchao opened 8 years ago

supengchao commented 8 years ago

之前一直在用volley,Afinal,xutils等http框架,用的太多了,早就听说retrofit,对他的印象是使用简单,方便,还可以使用OKhttp,一直没有机会研究,年前上线完公司的最后一版,终于有时间可以研究了,耶耶耶。。。

supengchao commented 8 years ago

start

先来小试一下,哈哈

retrofit的使用

看过好多关于retrofit方面的资料,觉得只有一篇是说的比较清晰条理的,个人推荐大家看下这篇文章 http://blog.csdn.net/lizelinll/article/details/42361327 使用retrofit前,先想明白要准备哪些材料,就像做饭一样 从什么开始呢?? 先看看retrofit给我们提供了哪些吧 1、RestAdapter---这是什么鬼?适配器有什么用呢?别急,慢慢来 先RestAdapter给我们准备了哪些材料,(好期待啊) RestAdapter singleton;
(1)得到你---RestAdapter.Builder mRestAdapter = new RestAdapter.Builder(); ---singleton= mRestAdapter.build(); (2)调戏你---setEndpoint 原来是让我们设置url 的ip地址的哦,这下明白了 ---setConverter 设置接口给我们放回数据的model,这样就可以直接得到对象了哦 ---setClient 建议使用okhttp,这里使用设置为okclient ---setLogLevel 设置是否要打印log,有2种方式,RestAdapter.LogLevel.FULL, RestAdapter.LogLevel.NONE (3)使用你--singleton.create(); 哈哈,是不是使用很简单。上面仅仅是使用的一部分,详细的源码分析请大家参考下面的这篇文章 http://my.oschina.net/freestyletime/blog/296371

ldy441040480 commented 8 years ago

你这都是老版本了。。。

supengchao commented 8 years ago

恩 是啊,你给补充下新版本的使用呗,有代码最好

supengchao commented 8 years ago

恩 是啊,你给补充下新版本的使用呗,有代码最好