注解类
lombok
implementation 'org.projectlombok:lombok:1.18.20'
@getter
@setter
@Data
网络请求
数据解析:gson
implementation 'com.google.code.gson:gson:2.7'
val gson = Gson()
dataBeanList = gson.fromJson(resultStr,DataBean::class.javaObjectType)
数据转换:GsonFormat
将json字符串转换成一个Java Bean
网络请求框架
okhttp
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
/**get同步请求**/
fun getSync(){
val client = OkHttpClient()
val request = Request.Builder()
.url(url)
.get() //默认为get,可省略该步
// .post(value) //value为提交的数据
.build()
Thread{
try{
val response : Response = client.newCall(request).execute()
val resultStr : String = response.body!!.string()
runOnUiThread(...)
} catch (e: IOException) {
e.printStackTrace()
}
}.start()
/**get异步请求**/
fun getAsync(){
val client = OkHttpClient()
val request = Request.Builder()
.url(url)
.get() //默认为get,可省略该步
// .post(value) //value为提交的数据
.build()
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
if (response.isSuccessful()){
response.body().toString();
}
}
});
runOnUiThread:activity特有的,若要在fragment中使用:
activity.runOnUiThread(...) //kotlin
getActivity.runOnUiThread(...) //java
POST提交的数据编码方式有多种
具体可见:https://www.runoob.com/http/http-content-type.html
//数据被编码为键值对的方式,默认类型
FormBody formBody = new FormBody.Builder()
.add("nameData", name)
.add("ageData", age)
.build();
//数据被编码为一条信息,一般用于文件上传
//提交二进制数据,若用于文件上传,只能上传一个
//提交json数据
retrogit
图片载入
Glide
Glide.with(getContext())
.load(url)
.into(imageview); .
Coil
利用了Kotlin的协程实现,所以只能用与kotlin,不能用于java
imageview.load(url)
注释:BugKotlinDocument
插件主页
功能:kotlin中生成类、方法的注释。
使用:在需要添加注释的类或方法上方,输入“ /** ”并回车。


5139

被折叠的 条评论
为什么被折叠?



