首页 > 其他分享 >后端兼容app新旧版本的功能

后端兼容app新旧版本的功能

时间:2024-08-20 23:05:17浏览次数:7  
标签:String 版本号 app 兼容 version 新旧 versionArray parseInt Integer

在开发中,有时需要对 app的新版本和旧版本,做不同的处理。可以根据版本号判断。

新版本app交互有变化时,同一个接口在 不同版本可能要返回不同的数据。

如果不区分新旧版本,有可能会导致旧版本app 不可用。

比如 1.2.1 的旧版本有一个功能是跳转 微信,到了 3.5.1 版本修改了 app的交互,变成跳转 微信小程序,如果不区分处理,旧版本就没法使用了。


示例:

public class VersionUtil {

    private static final String SPLIT_CHAR = "\\.";
    private static final String SPLIT = ".";


    /**
     * 检查版本
     * @param version    要检查的版本号,格式类似:3.5.1
     * @param oldVersion    旧版本号,格式类似:1.2.1,缺少的需补0.
     * @return 返回对应的数字
     */
    public static int checkVersion(String version, String oldVersion) {
        if (StringUtils.isBlank(version) || !version.contains(SPLIT)) {
            throw new IllegalArgumentException("请输入正确格式的版本号");
        }
        //点号做分隔符,需要做转义处理
        return checkVersion( version, oldVersion,  0,  1, SPLIT_CHAR);
    }

    /**
     * 检查版本
     * @param version    要检查的版本号,格式类似:3.5.1
     * @param oldVersion    旧版本号,格式类似:1.2.1,缺少的需补0.
     * @param oldVersionNum   旧版本号对应的数字
     * @param newVersionNum   新版本号对应的数字
     * @param splitChar  类似  "\\."
     * @return 返回对应的数字
     */
    public static int checkVersion(String version, String oldVersion, Integer oldVersionNum, Integer newVersionNum, String splitChar) {
        if (StringUtils.isBlank(version)  ) {
            throw new IllegalArgumentException("请输入正确格式的版本号");
        }
        if (StringUtils.isBlank(oldVersion)  ) {
            throw new IllegalArgumentException("请输入正确格式的旧版本号");
        }

        String[] versionArray = version.split(splitChar);
        String[] oldVersionArray = oldVersion.split(splitChar);

        if (versionArray.length >= 1 && Integer.parseInt(versionArray[0]) > Integer.parseInt(oldVersionArray[0])) {
            return newVersionNum;
        }
        if (versionArray.length >= 2  && Integer.parseInt(versionArray[0]) == Integer.parseInt(oldVersionArray[0])
                && Integer.parseInt(versionArray[1]) > Integer.parseInt(oldVersionArray[1])) {
            return newVersionNum;
        }
        if (versionArray.length >= 3  && Integer.parseInt(versionArray[0]) == Integer.parseInt(oldVersionArray[0])
                && Integer.parseInt(versionArray[1]) == Integer.parseInt(oldVersionArray[1])
                && Integer.parseInt(versionArray[2]) > Integer.parseInt(oldVersionArray[2])) {
            return newVersionNum;
        }
        return oldVersionNum;
    }


}

标签:String,版本号,app,兼容,version,新旧,versionArray,parseInt,Integer
From: https://www.cnblogs.com/expiator/p/18370531

相关文章

  • 红出圈的Bigo Ads推广美国休闲游戏APP广告核心优势
    BIGOAds是BIGO公司为全球市场提供的移动互联网广告业务营销平台,重点深耕中东,南亚,东南亚,俄罗斯等地区,旗下聚合两大王牌产品imo和Likee,以海量的用户数据和高质的内容生态为支撑,创意组合多元化广告玩法,致力于为全球合作伙伴提供一站式的商业化营销解决方案。BIGOAds优势庞大的......
  • uni-app vue3 实现微信朋友圈和朋友分享功能
     1.新建share.jsexportdefault{data(){return{}},//1.配置发送给朋友onShareAppMessage(){return{title:'分享的标题',//分享的标题path:'pages/index',//点击分享链接之后进入的页面路径imageUrl:''//分享发......
  • Android CDD(兼容性定义文档)
    1.什么是AndroidCDDAndroid兼容性定义文档(CDD)列举了设备需要满足哪些要求才能与最新的Android版本兼容。也就是说每当Android新版本更新时,我们需要检查Android最新的CDD,保证我们的系统满足AndroidCDD的要求。设备实现必须满足此兼容性定义文档(包括以参考资料的形式纳入......
  • 《深入探究 @SpringBootApplication 注解的内部原理》
    《深入探究@SpringBootApplication注解的内部原理》@SpringBootApplication注解涵盖了SpringBoot的包扫描原理、自动装配原理等众多重要原理。接下来,我们将对该注解展开深入且详尽的研究。而研究上述原理的关键,在于剖析@SpringBootApplication内部的构成结构,如下图:......
  • [Web Component] using `part` to allow applying styling from outside the shadow D
    Let'ssaywehaveawebcomponent: import{getProductById}from"../services/Menu.js";import{addToCart}from"../services/Order.js";exportdefaultclassDetailsPageextendsHTMLElement{constructor(){super();......
  • 国产海光CPU平台兼容性指南-基础软件分册-20231013(附各系统下载链接)
    目录声明一、操作系统 二、虚拟化和云2.1 虚拟化和云2.2虚拟机上的操作系统2.2.1 VMwarevSphere上的虚拟机操作系统2.2.2  KVM上的虚拟机操作系统2.2.3  WindowsHyper-V上的虚拟机操作系统2.2.4  VirtualBox上的虚拟机操作系统三、分布式存储 四、......
  • 创建uni-app项目(vue3+ts+vite)
     npxdegitdcloudio/uni-preset-vue#vite-tsm-uni-demo1跳转到对应目录,装包,运行cdm-uni-demo1yarnyarndev:h5tsconfig.json:{"extends":"@vue/tsconfig/tsconfig.json","compilerOptions":{"ignoreDeprecations&quo......
  • uniapp微信小程序的拍照功能
    1.实现的效果2.实现代码(1)pages/index/index中<template> <viewclass="content"> <imageclass="logo"src="/static/header.jpg"></image> <viewclass="text-area"> <buttonclass="......
  • uni_app中使用uQRcode生成二维码并保存到本地
    #效果#1.首先在插件市场引入uQRcode二维码生成插件,下载并导入到项目uQRCode全端二维码生成插件支持nvue支持nodejs服务端-DCloud插件市场https://ext.dcloud.net.cn/plugin?id=12872.在项目中新建vue文件,代码如下<template> <viewclass="code"> <viewclass="uqr......
  • Android 10.0 Launcher3从首页开始安装app功能实现
    1.前言 在10.0的系统rom定制化开发中,在进行Launcher3的某些功能开发实现过程中,在某些项目中,安装的app比较多,要求在launcher3的首页开始安装app应用,接下来就需要分析下app安装图标排序的流程,然后在实现相关的功能2.Launcher3从首页开始安装app功能实现的核心类packages/a......