当前位置: 首页 > news >正文

网络请求 mvp mvvm get post delete put 请求

get  参数拼接 如下接口

localhost:8080/uav/plotting/page/app?pageNum=1&pageSize=10&appId=e3c59e28-2032-4ddf-a762-7cec96f772a4&orgId=65&plottingType=point

@GET("https:/uav/plotting/page/app")
Observable<PlotList.DataBean> allPointList(@Query("pageNum") String pageNum, @Query("pageSize") String pageSize, @Query("appId") String appId, @Query("orgId") String orgId, @Query("itemCode") String itemCode, @Query("plottingType") String plottingType);

get 直接拼接url  如下接口

localhost:8080/uav/uav/info/bind/5YSZK9P0020BKU,1581F5FHB229F00201W1

@Header("Authorization") 是我项目的token 认证授权 
@GET("/uav/uav/info/bind/{aircraftSn}")Observable<BindOrgBean.DataBean> getBindOrgStutas(@Header("Authorization") String authorization, @Path("aircraftSn") String aircraftSn);

psot 参数拼接 如下接口https://test.uav.gafss.work/uav/uav/info/bind

    @Headers({"Content-Type: application/json"})@POST("/uav/uav/info/bind")Observable<BindOrg.DataBean> bindTissue(@Header("Authorization") String authorization, @Body String params);HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("appId", appId);
hashMap.put("orgId", orgId);
hashMap.put("uavNum", uavNum);
hashMap.put("itemCode", itemCode);String params = new Gson().toJson(hashMap);return NetWorkManager.getRequest().bindTissue(authorization,params);
delete参数拼接如下接口 localhost:8080/uav/plotting?ids=a667d699-4995-4370-8ab8-908da163047f
    @Headers({"Content-Type: application/json"})@POST("/uav/plotting/update/app")Observable<AddDot> editPoint(@Body String params);

put 参数拼接如下接口口 localhost:8080/ /uav/v2/titem/item/{uav_num} 

{

    "itemCode": "一风基分质布联",

    "inviteCode": "出了放指",

    "appId": "自听没个",

    "orgId": -2464645433090784

}

   @PUT("/uav/v2/titem/item")Observable<AddProject.DataBean> addProject(@Header("Authorization") String authorization,@Body String params);

下面是给服务器传集合 或者 json 

public class BindTissueModel implements BindTissueContact.Model {@Overridepublic Observable<Response<ArrayList<BindOrg.DataBean>>> bingTissue(String authorization, String appId, String orgId, String uavNum, String itemCode) {HashMap<String, Object> hashMap = new HashMap<>();hashMap.put("appId", appId);hashMap.put("orgId", orgId);hashMap.put("uavNum", uavNum);hashMap.put("itemCode", itemCode);String params = new Gson().toJson(hashMap);return NetWorkManager.getRequest().bindTissue(authorization,params);}@Overridepublic Observable<Response<ArrayList<CutOrgItem.BindDevicesBean>>> cutOrgItem(String authorization,  ArrayList<CutOrgItem.BindDevicesBean> list) {HashMap<String, Object> hashMap = new HashMap<>();hashMap.put("bindDevices", list);String params = new Gson().toJson(hashMap);return NetWorkManager.getRequest().cutOrgItem(authorization,params);}
}

接下来是完整的  

NetWorkManager.class
package com.bjdj.droneflyV5.net;import static androidx.core.view.OneShotPreDrawListener.add;import androidx.annotation.NonNull;import com.bjdj.droneflyV5.common.FlyApplication;
import com.bjdj.droneflyV5.net.interceptor.DownloadInterceptor;
import com.bjdj.droneflyV5.net.request.RequestApi;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;import kotlin.Pair;
import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;/*** Created by Zaifeng on 2018/2/28.* API初始化类*/public class NetWorkManager {private static NetWorkManager mInstance;private static Retrofit retrofit;private static volatile RequestApi request = null;public static NetWorkManager getInstance() {if (mInstance == null) {synchronized (NetWorkManager.class) {if (mInstance == null) {mInstance = new NetWorkManager();}}}return mInstance;}/*** 初始化必要对象和参数*/public void init() {
//        List<Protocol> protocols = new ArrayList<Protocol>() {{add(Protocol.HTTP_1_1); // <-- The only protocol used
//            add(Protocol.HTTP_2);
//        }};// 初始化okhttpHttpLoggingInterceptor logging = new HttpLoggingInterceptor();logging.setLevel(HttpLoggingInterceptor.Level.BODY);// 构建 OkHttpClient 时,将 OkHttpClient.Builder() 传入 with() 方法,进行初始化配置OkHttpClient client = RetrofitUrlManager.getInstance().with(new OkHttpClient.Builder()).readTimeout(40, TimeUnit.SECONDS).addInterceptor(logging).build();Gson gson = new GsonBuilder().setLenient().create();// 初始化Retrofitretrofit = new Retrofit.Builder().client(client)
//                .baseUrl(RequestApi.HOST).baseUrl(Objects.requireNonNull(FlyApplication.getInstance().getApiHost().getHost())).addConverterFactory(ScalarsConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create(gson)).build();//自定义OkHttpClient对象// GsonConverterFactory.create(gson))
//        RxHttpPlugins.init(client)
//                .setDebug(true,true,5) ;     //是否开启调试模式、是否分段打印、打印json数据缩进空格数量
//                .setCache(File, long,CacheMode)  //配置缓存目录,最大size及缓存模式
//                .setExcludeCacheKeys(String...)   //设置一些key,不参与cacheKey的组拼
//                .setResultDecoder(Function)       //设置数据解密/解码器,非必须
//                .setConverter(IConverter)         //设置全局的转换器,非必须
//                .setOnParamAssembly(Consumer);    //设置公共参数/请求头回调}public static RequestApi getRequest() {if (request == null) {synchronized (RequestApi.class) {request = retrofit.create(RequestApi.class);}}return request;}}
  /*** 绑定设备*/@Headers({"Content-Type: application/json"})@POST("/uav/uav/info/bind")Observable<Response<ArrayList<BindOrg.DataBean>>> bindTissue(@Header("Authorization") String authorization, @Body String params);创建接口 view层public interface BindTissueContact {interface Model {Observable<Response<ArrayList<BindOrg.DataBean>>> bingTissue(String authorization, String appId, String orgId, String uavNum, String itemCode);}interface View extends BaseView {@Overridevoid showLoading();@Overridevoid hideLoading();@Overridevoid onError(String errMessage);void getBindTissue(Response<ArrayList<BindOrg.DataBean>> bindTissue);}interface Presenter {void bingTissue(String authorization, String appId, String orgId, String uavNum, String itemCode);}
}创建model层public class BindTissueModel implements BindTissueContact.Model {@Overridepublic Observable<Response<ArrayList<BindOrg.DataBean>>> bingTissue(String authorization, String appId, String orgId, String uavNum, String itemCode) {HashMap<String, Object> hashMap = new HashMap<>();hashMap.put("appId", appId);hashMap.put("orgId", orgId);hashMap.put("uavNum", uavNum);hashMap.put("itemCode", itemCode);String params = new Gson().toJson(hashMap);return NetWorkManager.getRequest().bindTissue(authorization,params);}}
创建p层public class BindTissuePresenter implements BindTissueContact.Presenter {private final BindTissueModel bindTissueModel;private final BindTissueContact.View view;public BindTissuePresenter(BindTissueModel bindTissueModel, BindTissueContact.View view) {this.bindTissueModel = bindTissueModel;this.view = view;}@Overridepublic void bingTissue(String authorization, String appId, String orgId, String uavNum, String itemCode) {bindTissueModel.bingTissue(authorization,appId,orgId,uavNum,itemCode).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Response<ArrayList<BindOrg.DataBean>>>() {@Overridepublic void onSubscribe(Disposable d) {view.showLoading();}@Overridepublic void onNext(Response<ArrayList<BindOrg.DataBean>> orgProject) {view.getBindTissue(orgProject);}@Overridepublic void onError(Throwable e) {view.onError(e.getMessage());}@Overridepublic void onComplete() {view.hideLoading();}});}}接下来就是 activity 或者  fragment 实现view 层 接口 public class BindOrgActivity extends AppCompatActivity implements BindTissueContact.View {public static final String TAG = "BindOrgActivity";private BindTissuePresenter bindTissuePresenter;private String accessToken;private String aircraftSn, uavNum, isLogin;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);RxBarTool.hideStatusBar(this);setContentView(R.layout.activity_bind_org);initview();initData();}private void initview() {}private void initData() {bindTissuePresenter = new BindTissuePresenter(new BindTissueModel(), this);bindTissuePresenter.bingTissue(accessToken, appId, orgId, aircraftSn, itemCode);}@Overridepublic <T> AutoDisposeConverter<T> bindAutoDispose() {return null;}@Overridepublic void showLoading() {}@Overridepublic void hideLoading() {}@Overridepublic void onError(String errMessage) {}/** 绑定组织* */@SuppressLint("ResourceAsColor")@Overridepublic void getBindTissue(Response<ArrayList<BindOrg.DataBean>> bindTissue) {if (bindTissue.getCode() == 200) {Toast.makeText(this, "绑定成功", Toast.LENGTH_SHORT).show();status.setText("已绑定");status.setTextColor(R.color.black);}}}

BaseView 

public interface BaseView {/*** 显示加载中*/void showLoading();/*** 隐藏加载*/void hideLoading();/*** 数据获取失败* @param errMessage*/void onError(String errMessage);/*** 绑定Android生命周期 防止RxJava内存泄漏** @param <T>* @return*/<T> AutoDisposeConverter<T> bindAutoDispose();}

相关文章:

网络请求 mvp mvvm get post delete put 请求

get 参数拼接 如下接口 localhost:8080/uav/plotting/page/app?pageNum1&pageSize10&appIde3c59e28-2032-4ddf-a762-7cec96f772a4&orgId65&plottingTypepoint GET("https:/uav/plotting/page/app") Observable<PlotList.DataBean> allPoin…...

研究生开题报告撰写:文言一心VSChatgpt3.5

文言一心 问&#xff1a;我是一名研二学生&#xff0c;请帮我生成一份研究生毕设开题答辩ppt框架。 答&#xff1a;好的&#xff0c;以下是一份研究生毕设开题答辩PPT的框架&#xff0c;供您参考&#xff1a; 幻灯片1&#xff1a;封面页 标题&#xff1a;研究生毕设开题答辩…...

Unity animator动画倒放的方法

在Unity中&#xff0c; 我们有时候不仅需要animator正放的效果&#xff0c;也需要倒放的效果。但我们在实际制作动画的时候可以只制作一个正放的动画&#xff0c;然后通过代码控制倒放。 实现方法其实很简单&#xff0c;只需要把animator动画的speed设置为-1即为倒放&#xff…...

Dubbo源码解析第一期:如何使用Netty4构建RPC

一、背景 早期学习和使用Dubbo的时候&#xff08;那时候Dubbo还没成为Apache顶级项目&#xff09;&#xff0c;写过一些源码解读&#xff0c;但随着Dubbo发生了翻天覆地的变化&#xff0c;那些文章早已过时&#xff0c;所以现在计划针对最新的Apache Dubbo源码来进行“阅读理解…...

unity刷新grid,列表

获取UIGrid 组件&#xff0c;更新列表 listParent.GetComponent().repositionNow true;...

蓝桥杯备赛 day 3 —— 高精度(C/C++,零基础,配图)

目录 &#x1f308;前言&#xff1a; &#x1f4c1; 高精度的概念 &#x1f4c1; 高精度加法和其模板 &#x1f4c1; 高精度减法和其模板 &#x1f4c1; 高精度乘法和其模板 &#x1f4c1; 高精度除法和其模板 &#x1f4c1; 总结 &#x1f308;前言&#xff1a; 这篇文…...

人形机器人创新发展顶层设计与关键技术布局

系列文章目录 前言 随着新一轮科技革命和产业变革的深入推进&#xff0c;我国高度重视人形机器人的创新发展&#xff0c;提出了一系列具有前瞻性和战略性的指导意见。规划指出&#xff0c;到2025年&#xff0c;我国将初步建立人形机器人创新体系&#xff0c;攻克“大脑”、“小…...

C语言-算法-最小生成树

【模板】最小生成树 题目描述 如题&#xff0c;给出一个无向图&#xff0c;求出最小生成树&#xff0c;如果该图不连通&#xff0c;则输出 orz。 输入格式 第一行包含两个整数 N , M N,M N,M&#xff0c;表示该图共有 N N N 个结点和 M M M 条无向边。 接下来 M M M 行…...

android 扫描某个包下的所有类

注意事项 如果在用Android Studio开发过程中&#xff0c;如果新增了类&#xff0c;扫描不到。只能把APP卸载了&#xff0c;才能扫描到。 可能是Instance Run 的影响。 后面研究一下这篇文章&#xff0c;看看能不能解决 Android 遍历Apk下的所有类文件 package com.trs.nmip.…...

远程ssh 不通的原因之一

背景&#xff1a;我都想大喊一声&#xff0c;我上网是通的&#xff0c; ping网址是通的&#xff0c;ping www.baidu.com 是通的&#xff0c; 怎么都远程不了&#xff0c;报超时&#xff1b;嘿&#xff0c; 别人远程就能行。我都想挠头了。 目录 1. 先 ping 自己&#xff0c;…...

wamp集成环境部署

Windows下Apache服务器搭建 第一步&#xff1a;下载Windows下的最新ZIP压缩包 推荐下载网址&#xff1a;http://www.apachelounge.com/download/ 为了让Apache服务器发挥更好的性能&#xff0c;请根据自己的系统选择下载&#xff0c;如果不清楚自己的系统是64位还是32位&am…...

使用antd design pro 及后端nodejs express 结合minio进行文件的上传和下载管理

使用Ant Design Pro前端框架结合Node.js Express后端服务以及MinIO作为对象存储&#xff0c;实现文件上传和下载管理的基本步骤如下&#xff1a; 1. 安装所需依赖 在Node.js Express项目中安装minio客户端库&#xff1a; npm install minio --save 在前端项目&#xff08;假…...

Unity常用的优化技巧集锦

Unity性能优化是面试的时候经常被问道的一些内容&#xff0c;今天给大家分享一些常用的Unity的优化技巧和思路&#xff0c;方便大家遇到问题时候参考与学习。 对啦&#xff01;这里有个游戏开发交流小组里面聚集了一帮热爱学习游戏的零基础小白&#xff0c;也有一些正在从事游…...

c++动态调用dll

在C中动态调用DLL&#xff08;动态链接库&#xff09;可以使用Windows API函数。以下是一个简单的示例&#xff0c;演示如何动态加载和调用DLL中的函数&#xff1a; #include <windows.h> #include <iostream>int main() { // 加载DLL HMODULE hModule LoadLibrar…...

使用Python自动化操作手机,自动执行常见任务,例如滑动手势、呼叫、发送短信等等

使用Python自动化操作手机,自动执行常见任务,例如滑动手势、呼叫、发送短信等等。 此自动化脚本将帮助你使用 Python 中的 Android 调试桥 (ADB) 自动化你的智能手机。下面我将展示如何自动执行常见任务,例如滑动手势、呼叫、发送短信等等。 您可以了解有关 ADB 的更多信息,…...

E - Souvenir(图论典型例题)

思路&#xff1a;对于有很多询问的题&#xff0c;一般都是先初始化。我们求出每个点到其他点的最短路径以及相同路径下最大的价值和即可。 代码&#xff1a; #include <bits/stdc.h> #define pb push_back #define a first #define b second using namespace std; type…...

【SpringBoot篇】添加富文本编辑器操作

文章目录 &#x1f354;使用步骤⭐首先我们需要安装富文本编辑器⭐在<script>中引入富文本编辑器⭐富文本图片上传接口⭐初始化富文本编辑器⭐调用 初始化富文本编辑器的方法&#x1f388;新增&#x1f388;编辑&#x1f388;保存 ⭐添加按钮⭐实现viewEditor函数&#x…...

前台vue配置

前台 vue环境 1.傻瓜式安装node: 官网下载&#xff1a;https://nodejs.org/zh-cn/2.安装cnpm: >: npm install -g cnpm --registryhttps://registry.npm.taobao.org3.安装vue最新脚手架: >: cnpm install -g vue/cli注&#xff1a;如果2、3步报错&#xff0c;清除缓…...

牛客周赛 Round 18 解题报告 | 珂学家 | 分类讨论计数 + 状态DP

前言 整体评价 前三题蛮简单的&#xff0c;T4是一个带状态的DP&#xff0c;这题如果用背包思路去解&#xff0c;不知道如何搞&#xff0c;感觉有点头痛。所以最后还是选择状态DP来求解。 欢迎关注 珂朵莉 牛客周赛专栏 珂朵莉 牛客小白月赛专栏 A. 游游的整数翻转 这题最好…...

CentOS防火墙基本操作

CentOS操作系统中的防火墙可以使用firewalld或iptables来进行配置。 firewalld&#xff08;默认&#xff09;&#xff1a; 查看当前状态&#xff1a;systemctl status firewalld 开启/关闭防火墙服务&#xff1a;sudo systemctl start/stop firewalld 设置开机自动启动/不启…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

2025年能源电力系统与流体力学国际会议 (EPSFD 2025)

2025年能源电力系统与流体力学国际会议&#xff08;EPSFD 2025&#xff09;将于本年度在美丽的杭州盛大召开。作为全球能源、电力系统以及流体力学领域的顶级盛会&#xff0c;EPSFD 2025旨在为来自世界各地的科学家、工程师和研究人员提供一个展示最新研究成果、分享实践经验及…...

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility 1. 实验室环境1.1 实验室环境1.2 小测试 2. The Endor System2.1 部署应用2.2 检查现有策略 3. Cilium 策略实体3.1 创建 allow-all 网络策略3.2 在 Hubble CLI 中验证网络策略源3.3 …...

STM32F4基本定时器使用和原理详解

STM32F4基本定时器使用和原理详解 前言如何确定定时器挂载在哪条时钟线上配置及使用方法参数配置PrescalerCounter ModeCounter Periodauto-reload preloadTrigger Event Selection 中断配置生成的代码及使用方法初始化代码基本定时器触发DCA或者ADC的代码讲解中断代码定时启动…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...

【服务器压力测试】本地PC电脑作为服务器运行时出现卡顿和资源紧张(Windows/Linux)

要让本地PC电脑作为服务器运行时出现卡顿和资源紧张的情况&#xff0c;可以通过以下几种方式模拟或触发&#xff1a; 1. 增加CPU负载 运行大量计算密集型任务&#xff0c;例如&#xff1a; 使用多线程循环执行复杂计算&#xff08;如数学运算、加密解密等&#xff09;。运行图…...

leetcodeSQL解题:3564. 季节性销售分析

leetcodeSQL解题&#xff1a;3564. 季节性销售分析 题目&#xff1a; 表&#xff1a;sales ---------------------- | Column Name | Type | ---------------------- | sale_id | int | | product_id | int | | sale_date | date | | quantity | int | | price | decimal | -…...

20个超级好用的 CSS 动画库

分享 20 个最佳 CSS 动画库。 它们中的大多数将生成纯 CSS 代码&#xff0c;而不需要任何外部库。 1.Animate.css 一个开箱即用型的跨浏览器动画库&#xff0c;可供你在项目中使用。 2.Magic Animations CSS3 一组简单的动画&#xff0c;可以包含在你的网页或应用项目中。 3.An…...

[免费]微信小程序问卷调查系统(SpringBoot后端+Vue管理端)【论文+源码+SQL脚本】

大家好&#xff0c;我是java1234_小锋老师&#xff0c;看到一个不错的微信小程序问卷调查系统(SpringBoot后端Vue管理端)【论文源码SQL脚本】&#xff0c;分享下哈。 项目视频演示 【免费】微信小程序问卷调查系统(SpringBoot后端Vue管理端) Java毕业设计_哔哩哔哩_bilibili 项…...

【C++进阶篇】智能指针

C内存管理终极指南&#xff1a;智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...