SQLiteDataBase数据库
XML界面设计
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="姓名:" /><EditTextandroid:id="@+id/etc_name"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="50px" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="班级:" /><EditTextandroid:id="@+id/etc_class"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="50px" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="学号:" /><EditTextandroid:id="@+id/etc_id"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="50px" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/btn_add"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="添加数据"android:textAlignment="center" /><Buttonandroid:id="@+id/btn_show"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="全部显示"android:textAlignment="center" /><Buttonandroid:id="@+id/btn_clr"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="清除数据"android:textAlignment="center" /><Buttonandroid:id="@+id/btn_del"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="全部删除"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="ID:" /><EditTextandroid:id="@+id/etc_id2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="2" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><Buttonandroid:id="@+id/btn_del_id"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="ID删除"android:textAlignment="center" /><Buttonandroid:id="@+id/btn_show_id"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="ID查询"android:textAlignment="center" /><Buttonandroid:id="@+id/btn_update_id"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:text="ID更新"android:textAlignment="center" /></LinearLayout><TextViewandroid:id="@+id/txt_end"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="" /><ListViewandroid:id="@+id/list"android:layout_width="match_parent"android:layout_height="wrap_content"/></LinearLayout>
People.java
package com.example.exp6;public class People {public int ID = -1;public String Name;public String Class;public String Number;//重载toString方法 返回值String类型@Overridepublic String toString(){String result = "";result += "ID:" + this.ID + ",";result += "姓名:" + this.Name + ",";result += "班级:" + this.Class + ", ";result += "学号:" + this.Number;return result;}
}
DBAdapter.java
package com.example.exp6;
import android.annotation.SuppressLint;
import android.content.*;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;import androidx.annotation.Nullable;//对数据库进行操作的类
public class DBAdapter {private static final String DB_NAME = "student.db"; //数据库名称private static final String DB_TABLE = "peopleinfo"; //表名private static final int DB_VERSION = 1; //数据库版本public static final String KEY_ID = "_id"; //数据库表的属性名称public static final String KEY_NAME = "name";public static final String KEY_CLASS = "class";public static final String KEY_NUMBER = "number";private SQLiteDatabase db; //数据库的实例dbprivate final Context context; //Context的实例化private DBOpenHelper dbOpenHelper; //帮助类的实例化 dbOpenHelper//内部类:对帮助类 构建//继承SQLiteOpenHelper//必须重载onCreate和onUpgrade方法private static class DBOpenHelper extends SQLiteOpenHelper {//帮助类的构造函数 -- 4个参数//Code -> SQLiteOpenHelper 即可成功插入该构造函数public DBOpenHelper(@Nullable Context context, @Nullable String name,SQLiteDatabase.CursorFactory factory, int version) {super(context, name, factory, version);}//static常量字符串--创建表的 sql 命令//create table peopleinfo("id integer primary key autoincrement,name text not null,// class text not null,number text not null")private static final String DB_CREATE = "create table " +DB_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " +KEY_NAME + " text not null, " + KEY_CLASS + " text not null," +KEY_NUMBER + " text not null);";//重载帮助类onCreate方法//1个参数SQLiteDatabase类型@Overridepublic void onCreate(SQLiteDatabase sqLiteDatabase) {//execSQL()方法 1个String类型的 sql 建表命令sqLiteDatabase.execSQL(DB_CREATE);}//重载帮助类onUpdate方法//一般在升级的时候被调用//删除旧的数据库表 并将数据转移到新版本的数据库表//3个参数SQLiteDatabase类型、int i-旧版本号、int i1-新版本号@Overridepublic void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {//仅删除原表后建立新表sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);onCreate(sqLiteDatabase);}}//对数据库进行操作的类DBAdapter的构造//参数1个 Context类型public DBAdapter(Context _context) {context = _context;}//DBAdapter类的open方法//抛出异常!!!!public void open() throws SQLiteException {//帮助类实例化dbOpenHelper需要4个参数dbOpenHelper = new DBOpenHelper(context, DB_NAME,null, DB_VERSION);//调用getWritableDatabase方法try {db = dbOpenHelper.getWritableDatabase();} catch (SQLiteException ex) {db = dbOpenHelper.getReadableDatabase();}}//DBAdapter类的close方法public void close() {if (db != null) {db.close();db = null;}}//DBAdapter类的insert方法//参数1个:数据库储存的类型(本例是Peoplepublic long insert(People people) {//用ContentValues类型ContentValues newValues = new ContentValues();//在put的时候不需要put Key_ID!!!newValues.put(KEY_NAME, people.Name);newValues.put(KEY_CLASS, people.Class);newValues.put(KEY_NUMBER, people.Number);//返回值是新数据插入的位置 ID值//数据库对象.insert方法//参数3个:表名 在null时的替换数据 ContentValues类型需要添加的数据return db.insert(DB_TABLE, null, newValues);}//DBAdapter类的deleteAllData方法//无参数public long deleteAllData() {//返回值是被删除的数据的数量//参数3个:表名 删除条件(删除全部数据条件是null)return db.delete(DB_TABLE, null, null);}//DBAdapter类的deleteOneData方法//参数1个:long类型的id值public long deleteOneData(long id) {//返回值是被删除的数据的数量//参数3个:表名 删除条件(删除形参给的id)return db.delete(DB_TABLE, KEY_ID + "=" + id, null);}//DBAdapter类的UpdataOneData方法//参数2个:long类型的id值 和 People类型public long updateOneData(long id , People people){//更新和插入一样用到了ContentValues类型ContentValues updateValues = new ContentValues();//同样不需要放Key_IDupdateValues.put(KEY_NAME, people.Name);updateValues.put(KEY_CLASS, people.Class);updateValues.put(KEY_NUMBER, people.Number);//返回值是被更新的数据数量//参数4个 表明 ContentValues 更新条件string类型 nullreturn db.update(DB_TABLE, updateValues, KEY_ID + "=" + id, null);}//private类型//DBAdapter类的ConvertToPeople方法//参数1个 Cursor类型//返回People数组//查询需要基于该 ConvertToPeople 方法(应该是自定义方法?)@SuppressLint("Range")private People[] ConvertToPeople(Cursor cursor){//getCount方法返回查询结果总行数int resultCounts = cursor.getCount();//行数为0||moveToFirst方法返回false返回结果为空if (resultCounts == 0 || !cursor.moveToFirst()){//该方法返回nullreturn null;}//新建resultCounts个People对象People[] peoples = new People[resultCounts];//循环 resultCounts次for (int i = 0 ; i<resultCounts; i++){peoples[i] = new People();peoples[i].ID = cursor.getInt(0);//根据 列属性索引 得到 属性值peoples[i].Name = cursor.getString(cursor.getColumnIndex(KEY_NAME));peoples[i].Class = cursor.getString(cursor.getColumnIndex(KEY_CLASS));peoples[i].Number = cursor.getString(cursor.getColumnIndex(KEY_NUMBER));//游标/指针下移cursor.moveToNext();}//返回People[]return peoples;}//查询操作://DBAdapter类的getOneData方法//参数1个:long类型的id值public People[] getOneData(long id) {//query方法//参数7个(6String 1String[]):表名称 属性列-String[] 查询条件//查询条件是否使用通配符 分组条件 分组过滤条件 排序方式 后4个全是null//返回Cursor类型Cursor results = db.query(DB_TABLE, new String[] { KEY_ID, KEY_NAME, KEY_CLASS, KEY_NUMBER},KEY_ID + "=" + id, null, null, null, null);//返回People[]return ConvertToPeople(results);}//DBAdapter类的getAllData方法public People[] getAllData() {//参数查询条件为null 存在5个nullCursor results = db.query(DB_TABLE, new String[] { KEY_ID, KEY_NAME, KEY_CLASS, KEY_NUMBER},null, null, null, null, null);return ConvertToPeople(results);}}
MainActivity.java
package com.example.exp6;import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
import android.widget.ArrayAdapter;public class MainActivity extends AppCompatActivity {EditText etc_name,etc_class,etc_id,etc_id2;TextView txt_end;ListView listView;Button btn_add,btn_show,btn_clr,btn_del,btn_del_id,btn_show_id,btn_update_id;DBAdapter dbAdapter;SQLiteDatabase db;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);listView=findViewById(R.id.list);ArrayList<String> data=new ArrayList<String>();//数组适配器//实例化 参数3个ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);etc_name=findViewById(R.id.etc_name);etc_class=findViewById(R.id.etc_class);etc_id=findViewById(R.id.etc_id);btn_add=findViewById(R.id.btn_add);btn_show=findViewById(R.id.btn_show);btn_clr=findViewById(R.id.btn_clr);btn_del=findViewById(R.id.btn_del);btn_del_id=findViewById(R.id.btn_del_id);btn_show_id=findViewById(R.id.btn_show_id);btn_update_id= findViewById(R.id.btn_update_id);etc_id2=findViewById(R.id.etc_id2);txt_end=findViewById(R.id.txt_end);//处理数据库的类的实例对象//参数1个 Context类型dbAdapter=new DBAdapter(this);//调用DBAdapter对象的 open 方法dbAdapter.open();btn_add.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//将文本框中的内容用来创建对象PeoplePeople t=new People();t.Name=etc_name.getText().toString();t.Class=etc_class.getText().toString();t.Number=etc_id.getText().toString();//插入一个对象People//返回插入的位置idlong colunm=dbAdapter.insert(t);if (colunm == -1 ){txt_end.setText("添加过程错误!");} else {txt_end.setText("ID:"+String.valueOf(colunm)+" 姓名:"+t.Name+" 班级:"+t.Class+" 学号:"+t.Number);}}});btn_show.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//调用得到数据库中全部的信息People [] peoples =dbAdapter.getAllData();if (peoples == null){txt_end.setText("数据库中没有数据");return;}String t="数据库:\n";for(int i=0;i<peoples.length;++i){t += peoples[i].toString()+"\n";}txt_end.setText(t);}});btn_clr.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {txt_end.setText("");}});btn_del.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {dbAdapter.deleteAllData();txt_end.setText("已删除所有数据!");}});btn_del_id.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {int id=Integer.parseInt(etc_id2.getText().toString());//返回删除的数据的数量//参数要求int类型的long result=dbAdapter.deleteOneData(id);String msg = "删除ID为"+etc_id2.getText().toString()+"的数据" + (result>0?"成功":"失败");txt_end.setText(msg);}});btn_show_id.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {int id=Integer.parseInt(etc_id2.getText().toString());//查找方法 参数id-int//返回值是People[]People people[]=dbAdapter.getOneData(id);if(people==null){txt_end.setText("Id为"+id+"的记录不存在!");}else{//因为仅只查找了一条信息 所以是people[0]//并且在People类型中已经重载了函数toString()txt_end.setText("查询成功:\n"+people[0].toString());}}});btn_update_id.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {int id=Integer.parseInt(etc_id2.getText().toString());People t=new People();t.Name=etc_name.getText().toString();t.Class=etc_class.getText().toString();t.Number=etc_id.getText().toString();//更新方法//参数2个 id-int people类型//返回值 被更新的数据数量long n=dbAdapter.updateOneData(id,t);if (n<0){txt_end.setText("更新过程错误!");}else{txt_end.setText("成功更新数据,"+String.valueOf(n)+"条");}}});}@Overrideprotected void onStop() {super.onStop();dbAdapter.close();}
}
结果
数据添加(朱迪&尼克狐尼克)
全部显示
ID删除 (25-朱迪)
ID查询 (26)
ID更新 (26)
全部删除
全部显示
相关文章:

SQLiteDataBase数据库
XML界面设计 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.android.com/tools"android:layout_width"match_paren…...
STM32 高级 物联网通讯之蓝牙通讯
目录 蓝牙基础知识 蓝牙概述 蓝牙产生背景 蓝牙发展历程 蓝牙技术类型 经典蓝牙(BR/EDR和AMP) 低功耗蓝牙(BLE) 市场上常见蓝牙架构 SOC蓝牙单芯片方案 SOC蓝牙+MCU方案 蓝牙host+controller分开方案 蓝牙协议栈 蓝牙芯片架构 BLE低功耗蓝牙协议栈框架 物理…...

react中实现拖拽排序
效果图:如下 效果说明: 1. 点击“选择”按钮,打开弹窗 2. 左侧数据是调接口回显来的 3. 点击左侧某条数据,这条被点击的数据就会被添加到右侧 4. 右侧的数据可以上下拖动换位置 5. 右侧有数据时,点击"确定"…...
【华为OD-E卷-AI处理器组合100分(python、java、c++、js、c)】
【华为OD-E卷-AI处理器组合100分(python、java、c、js、c)】 题目 某公司研发了一款高性能AI处理器。每台物理设备具备8颗AI处理器,编号分别为0、1、2、3、4、5、6、7。 编号0-3的处理器处于同一个链路中,编号4-7的处理器处于另…...

语音识别基础算法——动态时间规整算法
前言 动态时间规整算法,Dynamic Time Wraping,缩写为DTW,是语音识别领域的一个基础算法。 算法的提出 DTW 的提出是为了解决或尽量解决在语音识别当中的孤立词识别不正确的问题。该问题简单描述为:在识别阶段,将输入…...

模型工作流:自动化的模型内部三角面剔除
1. 关于自动减面 1.1 自动减面的重要性及现状 三维模型是游戏、三维家居设计、数字孪生、VR/AR等几乎所有三维软件的核心资产,模型的质量和性能从根本上决定了三维软件的画面效果和渲染性能。其中,模型减面工作是同时关乎质量和性能这两个要素的重要工…...
解读一个新建的 Spring Boot 项目
解读一个新建的 Spring Boot 项目。 1. 创建 Spring Boot 2.5.6 项目 步骤 1: 使用 Spring Initializr 创建项目 可以使用 Spring Initializr(https://start.spring.io/)来快速生成一个 Spring Boot 项目。 在 Spring Initializr 中选择以下配置&…...

Vue多页面路由与模版解析
上篇文章中我们成功打包并输出了多页文件,而构建一个多页应用能够让我们进一步了解项目配置的可拓展性,可以对学习 Vue 和 webpack 起到强化训练的效果,本文将在此基础上主要针对多页路由及模板的配置进行系列的介绍。 本案例代码地址&#…...

Python爬虫(二)- Requests 高级使用教程
文章目录 前言一、Session 对象1. 简介2. 跨请求保持 Cookie3. 设置缺省数据4. 方法级别参数不被跨请求保持5. 会话作为上下文管理器6. 移除字典参数中的值 二、请求与响应1. 请求与响应对象1.1 获取响应头信息1.2 获取发送到服务器的请求头信息 三、SSL 证书验证1. 忽略 SSL 证…...

并联带阻滤波器带通滤波器对幅值和相位的影响(IIR)
一、背景 输入信号input分别经过bp(带通滤波器)和bs(带阻滤波器)处理后相加输出。分析输出信号的幅值和相位受到的影响。 根据上图公式推导可知,并联滤波器对输出的影响可以直接分析,带通滤波器与带阻滤波器在频域上的加和。 二、…...

攻防世界web新手第五题supersqli
这是题目,题目看起来像是sql注入的题,先试一下最常规的,输入1,回显正常 输入1‘,显示错误 尝试加上注释符号#或者–或者%23(注释掉后面语句,使1后面的单引号与前面的单引号成功匹配就不会报错…...

vue3学习笔记(10)-$subscribe,store组合式写法
1.$subscribe订阅,监视vuex中数据得修改 2.localStorage里面穿的都是字符串,关掉浏览器数据还在 只能获取字符串,用ts语法写明,作为字符串使用 3.组合式写法...

操作系统论文导读(八):Schedulability analysis of sporadic tasks with multiple criticality specifications——具有多个
Schedulability analysis of sporadic tasks with multiple criticality specifications——具有多个关键性规范的零星任务的可调度性分析 目录 一、论文核心思想 二、基本定义 2.1 关键性指标 2.2 任务及相关参数定义 2.3 几个基础定义 三、可调度性分析 3.1 调度算法分…...
计算机网络与通信复习
因特网的核心部分(电路交换与分组交换的不同点,分组交换的优点) 核心部分:路由器、交换机 我们假如数据就是一个货物,比如说一千公斤的大米,电路交换要有专用通道,不管从起点到终点经过多少个…...

【Scala】图书项目系统代码演练3.1/BookService
package org.app package serviceimport models.{BookModel, BorrowRecordModel}import org.app.dao.{BookDAO, BorrowRecordDAO}import java.time.LocalDateTime import scala.collection.mutable.ListBuffer// 图书业务逻辑层 class BookService {private val bookDAO new B…...

人工智能基础软件-Jupyter Notebook
简介: Jupyter Notebook是基于网页的用于交互计算的应用程序。其可被应用于全过程计算:开发、文档编写、运行代码和展示结果。 Jupyter Notebook是以网页的形式打开,可以在网页页面中直接编写代码和运行代码,代码的运行结果也会直…...
C++ 设计模式:模板方法(Template Method)
链接:C 设计模式 链接:C 设计模式 - 策略模式 链接:C 设计模式 - 观察者模式 模板方法(Template Method)是一种行为设计模式,它定义了一个操作中的算法的骨架,而将一些步骤延迟到子类中。通过这…...
GDPU Vue前端框架开发 跨年大礼包
目录 选择题 填空题 简答题 记住,年底陪你跨年的不会仅是方便面跟你的闺蜜,还有孑的笔记。 选择题 1.下列选项用于设置Vue.js页面视图的元素是()。 A. Template B. script C. style D. title 2.下列选项中能够定义Vuejs根…...
搭建一个高效且安全的APP分发平台
搭建一个高效且安全的APP分发平台需要经历一系列精心规划和实施的步骤。以下是一个详细的指南,涵盖从准备阶段到后续维护阶段的各个环节: 一、准备阶段 明确目标与需求 确定平台的目标用户群体,了解他们的需求和偏好。分析竞争对手的分发平台…...

Leetcode打卡:二叉树中的链表
执行结果:通过 题目 1367 二叉树中的链表 给你一棵以 root 为根的二叉树和一个 head 为第一个节点的链表。 如果在二叉树中,存在一条一直向下的路径,且每个点的数值恰好一一对应以 head 为首的链表中每个节点的值,那么请你返回 …...

SpringBoot-17-MyBatis动态SQL标签之常用标签
文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…...

业务系统对接大模型的基础方案:架构设计与关键步骤
业务系统对接大模型:架构设计与关键步骤 在当今数字化转型的浪潮中,大语言模型(LLM)已成为企业提升业务效率和创新能力的关键技术之一。将大模型集成到业务系统中,不仅可以优化用户体验,还能为业务决策提供…...

C++初阶-list的底层
目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...

[ICLR 2022]How Much Can CLIP Benefit Vision-and-Language Tasks?
论文网址:pdf 英文是纯手打的!论文原文的summarizing and paraphrasing。可能会出现难以避免的拼写错误和语法错误,若有发现欢迎评论指正!文章偏向于笔记,谨慎食用 目录 1. 心得 2. 论文逐段精读 2.1. Abstract 2…...

【SQL学习笔记1】增删改查+多表连接全解析(内附SQL免费在线练习工具)
可以使用Sqliteviz这个网站免费编写sql语句,它能够让用户直接在浏览器内练习SQL的语法,不需要安装任何软件。 链接如下: sqliteviz 注意: 在转写SQL语法时,关键字之间有一个特定的顺序,这个顺序会影响到…...
Linux云原生安全:零信任架构与机密计算
Linux云原生安全:零信任架构与机密计算 构建坚不可摧的云原生防御体系 引言:云原生安全的范式革命 随着云原生技术的普及,安全边界正在从传统的网络边界向工作负载内部转移。Gartner预测,到2025年,零信任架构将成为超…...

04-初识css
一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...
【服务器压力测试】本地PC电脑作为服务器运行时出现卡顿和资源紧张(Windows/Linux)
要让本地PC电脑作为服务器运行时出现卡顿和资源紧张的情况,可以通过以下几种方式模拟或触发: 1. 增加CPU负载 运行大量计算密集型任务,例如: 使用多线程循环执行复杂计算(如数学运算、加密解密等)。运行图…...
Axios请求超时重发机制
Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式: 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...
AI编程--插件对比分析:CodeRider、GitHub Copilot及其他
AI编程插件对比分析:CodeRider、GitHub Copilot及其他 随着人工智能技术的快速发展,AI编程插件已成为提升开发者生产力的重要工具。CodeRider和GitHub Copilot作为市场上的领先者,分别以其独特的特性和生态系统吸引了大量开发者。本文将从功…...