Android : SQLite 增删改查—简单应用
示例图:
学生实体类 Student.java
package com.example.mysqlite.dto;public class Student {public Long id;public String name;public String sex;public int age;public String clazz;public String creatDate;//头像public byte[] logoHead;@Overridepublic String toString() {return "Student{" +"id=" + id +", name='" + name + '\'' +", sex='" + sex + '\'' +", age=" + age +", clazz='" + clazz + '\'' +", creatDate='" + creatDate + '\'' +'}';}
}
工具类 DBhelpUtil.java
package com.example.mysqlite.util;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;import androidx.annotation.Nullable;public class DBhelpUtil extends SQLiteOpenHelper {/**数据库名字*/public static final String DB_NAME = "studentDB";/**学生表字段信息*/public static final String TABLE_NAME = "tb_student";public static final String TB_NAME = "name";public static final String TB_SEX = "sex";public static final String TB_AGE = "age";public static final String TB_CLAZZ = "clazz";public static final String TB_CREATEDATE = "createDate";/**数据版本号 第一次运行要打开 */
// public static final int DB_VERSION = 1;//模拟数据版本升级public static final int DB_VERSION = 2;/**** @param context 上下文* @param name 数据库名字* @param factory 游标工厂 null* @param version 自定义的数据库版本*/public DBhelpUtil(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {super(context, name, factory, version);}//数据库第一次创建时被调用@Overridepublic void onCreate(SQLiteDatabase db) {//初始化 第一次 创建数据库StringBuilder sql = new StringBuilder();sql.append(" create table tb_student(");sql.append(" id integer primary key, ");sql.append(" name varchar(20),");sql.append(" sex varchar(2),");sql.append(" age varchar(20),");sql.append(" clazz varchar(20),");sql.append(" createDate varchar(23) )");// Log.e("TAG","------"+sql.toString());//执行sqldb.execSQL(sql.toString());}//版本号发生改变时调用@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {//更新数据库 插入字段String sql = "alter table tb_student add logoHead varchar(200)";db.execSQL(sql);}
}
StudentDao.java
package com.example.mysqlite.dao;import android.content.ContentValues;
import android.content.Context;
import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.database.CursorWindow;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;import com.example.mysqlite.dto.Student;
import com.example.mysqlite.util.DBhelpUtil;import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;public class StudentDao {private DBhelpUtil dBhelpUtil;/**相当于获得一个链接数据库的对象*/private SQLiteDatabase DB;private Context context;public StudentDao(Context context,DBhelpUtil dBhelpUtil){this.context =context;this.dBhelpUtil = dBhelpUtil;}//保存数据public Long save(Student student) {/** 获取一个写 操作数据的对象*/DB = dBhelpUtil.getWritableDatabase();ContentValues contentValues = new ContentValues();contentValues.put(DBhelpUtil.TB_NAME,student.name);contentValues.put(DBhelpUtil.TB_SEX,student.sex);contentValues.put(DBhelpUtil.TB_AGE,student.age);contentValues.put(DBhelpUtil.TB_CLAZZ,student.clazz);// Log.e("TAG","--------------"+student.toString());
// Toast.makeText(context,"sql 语句--"+student.toString(),Toast.LENGTH_LONG).show();//时间Date date = new Date();//格式化SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");contentValues.put(DBhelpUtil.TB_CREATEDATE, simpleDateFormat.format(date));/**insert()* String table: 表名* String nullColumnHack: 不允许插入空行,为了防止插入空行,可以在这里随便指定一列, 如果有空值插入 会用null表示,好像没作用~* ContentValues values 数据行数据* 返回值 成功插入行号的id ,插入失败 -1*/return DB.insert(DBhelpUtil.TABLE_NAME,"空值",contentValues);//INSERT INTO tb_student(id,age,sex,name,clazz,createDate) VALUES (?,?,?,?,?,?)}/**查询数据*/public List<Student> select(Long id) {/** 获取一个读 操作数据的对象*/DB =dBhelpUtil.getReadableDatabase();/**query() 查询数据*String table, 表名* String[] columns, 要查询要显示的列* String selection, 查询条件* String[] selectionArgs, 参数值* String groupBy, 分组* String having, 分组后的条件* String orderBy 排序* 返回游标 Cursor*/String[] columns = new String[]{"id",DBhelpUtil.TB_NAME,DBhelpUtil.TB_SEX,DBhelpUtil.TB_AGE,DBhelpUtil.TB_CLAZZ,DBhelpUtil.TB_CREATEDATE};Cursor cursor = null;if(id == null){//全查cursor = DB.query(DBhelpUtil.TABLE_NAME,columns,null,null,null,null,"id desc");}else {//根据id 查询cursor = DB.query(DBhelpUtil.TABLE_NAME,columns,"id=?",new String[]{String.valueOf(id)},null,null,null);}List<Student> studentList = new ArrayList<>();if(cursor != null){//遍历游标while(cursor.moveToNext()){Student student = new Student();// 根据游标找到列 在获取数据student.id = cursor.getLong(cursor.getColumnIndexOrThrow("id"));student.name = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_NAME));student.sex = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_SEX));student.age = cursor.getInt(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_AGE));student.clazz = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_CLAZZ));student.creatDate = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_CREATEDATE));//添加到集合studentList.add(student);}}cursor.close();return studentList;}/**删除数据*/public int delete(Long id) {// 获取操作数据库对象DB = dBhelpUtil.getWritableDatabase();/*** String table, 表名* String whereClause, 条件* String[] whereArgs 参数* 返回影响行数,失败 0*///全部删除if(id == null){return DB.delete(DBhelpUtil.TABLE_NAME,null,null);}// 条件查询return DB.delete(DBhelpUtil.TABLE_NAME,"id = ?",new String[]{id+""});}/**保存位图*/public void saveBitmap(Student student) {/** 获取一个写 操作数据的对象*/DB = dBhelpUtil.getWritableDatabase();//开启事务DB.beginTransaction();//时间Date date = new Date();//格式化SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//执行sql语句 方式String sql = "INSERT INTO tb_student(age,sex,name,clazz,createDate,logoHead) VALUES (?,?,?,?,?,?)";/*** sql 语句* 要插入的数据*/DB.execSQL(sql,new Object[]{student.age,student.sex,student.name,student.clazz,simpleDateFormat.format(date),student.logoHead});//设置事务成功DB.setTransactionSuccessful();//添加事务DB.endTransaction();}//查询位图public Student selectBitmapById(Long id) {/** 获取一个读 操作数据的对象*/DB =dBhelpUtil.getReadableDatabase();Cursor cursor = null;/** 根据id 查询 返回一个游标对象* String sql,* String[] selectionArgs,* select * from tb_student where id = ?*/cursor = DB.rawQuery("select * from "+ DBhelpUtil.TABLE_NAME+" where id =?",new String[]{id+""});// 解决报错;android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=0, totalRows=1CursorWindow cw = new CursorWindow("test", 5000000); // 设置CursorWindow的大小为5000000AbstractWindowedCursor ac = (AbstractWindowedCursor) cursor;ac.setWindow(cw);Student student = null;if(cursor != null){if(cursor.moveToNext()){student = new Student();// 根据游标找到列 在获取数据student.id = cursor.getLong(cursor.getColumnIndexOrThrow("id"));student.name = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_NAME));student.sex = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_SEX));student.age = cursor.getInt(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_AGE));student.clazz = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_CLAZZ));student.creatDate = cursor.getString(cursor.getColumnIndexOrThrow(DBhelpUtil.TB_CREATEDATE));//图片student.logoHead =cursor.getBlob(cursor.getColumnIndexOrThrow("logoHead")) ;}}cursor.close();return student;}//按条件修改public int updateById(Student student,Long id){// 获取写操作数据库对象DB = dBhelpUtil.getWritableDatabase();//开启事务DB.beginTransaction();/*** String table,* ContentValues values, 数据行数据* String whereClause, 条件* String[] whereArgs 参数* 返回影响行数*///数据行数据ContentValues contentValues = new ContentValues();contentValues.put(DBhelpUtil.TB_NAME,student.name);contentValues.put(DBhelpUtil.TB_SEX,student.sex);contentValues.put(DBhelpUtil.TB_AGE,student.age);contentValues.put(DBhelpUtil.TB_CLAZZ,student.clazz);//时间Date date = new Date();//格式化SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");contentValues.put(DBhelpUtil.TB_CREATEDATE, simpleDateFormat.format(date));int result = DB.update(DBhelpUtil.TABLE_NAME,contentValues,"id = ?", new String[]{id+""});//完成事务DB.setTransactionSuccessful();//结束事务DB.endTransaction();return result;}
}
MainActivity.java
package com.example.mysqlite;import androidx.appcompat.app.AppCompatActivity;import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;import com.example.mysqlite.activity.BaseActivity;
import com.example.mysqlite.dao.StudentDao;
import com.example.mysqlite.dto.Student;
import com.example.mysqlite.util.DBhelpUtil;import java.io.ByteArrayOutputStream;
import java.util.List;public class MainActivity extends AppCompatActivity {private Context mContext;private EditText etName,etSex,etAge,etClass;private EditText etSelectID,etDeleteID;private Button btnSave,btnSelect,btnDelete,btnSaveBitmap,btnSelectBitmap,btnUpdate;private TextView textView;private ImageView imageView;private DBhelpUtil dBhelpUtil;private StudentDao studentDao;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mContext = this;etName = findViewById(R.id.et_name);etSex = findViewById(R.id.et_sex);etAge = findViewById(R.id.et_age);etClass = findViewById(R.id.et_class);etSelectID =findViewById(R.id.et_select_id);etDeleteID = findViewById(R.id.et_delete_id);textView =findViewById(R.id.tv_data);imageView = findViewById(R.id.iv_image);//按钮btnSave = findViewById(R.id.tbn_save);btnSelect = findViewById(R.id.tbn_select);btnDelete = findViewById(R.id.tbn_delete);btnSaveBitmap = findViewById(R.id.btn_save_bitmap);btnSelectBitmap = findViewById(R.id.tbn_select_bitmap);btnUpdate = findViewById(R.id.btn_update);/**** @param context 上下文* @param name 数据库名字* @param factory 游标工厂 null* @param version 自定义的数据库版本*/dBhelpUtil = new DBhelpUtil(mContext,DBhelpUtil.DB_NAME,null,DBhelpUtil.DB_VERSION);studentDao = new StudentDao(MainActivity.this,dBhelpUtil);//保存数据事件btnSave.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//保存数据方法setDataSave();}});// 查询事件btnSelect.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//查询数据selectDataByID();}});//修改事件btnUpdate.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {updateData();}});//删除事件btnDelete.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {deleteDataById();}});//跟新数据库版本后 增加了字段插入图片btnSaveBitmap.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {try {// 获取文本信息Student student = new Student();student.name = etName.getText().toString();student.sex = etSex.getText().toString();student.age = Integer.valueOf(etAge.getText().toString());student.clazz = etClass.getText().toString();//图片// 获取图片位图Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.logo);//字节数组输出流ByteArrayOutputStream out = new ByteArrayOutputStream();/** 把位图 转换 成字节数组输出流*CompressFormat format, 格式* int quality, 质量 0 - 100* OutputStream stream 输出流*/bitmap.compress(Bitmap.CompressFormat.JPEG,100,out);student.logoHead = out.toByteArray();studentDao.saveBitmap(student);showToast("保存数据成功!");}catch (Exception e){showToast("保存数据失败"+e.getMessage());}}});//查询展示图片btnSelectBitmap.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {selectBitmapMethod();}});}/**保存数据*/public void setDataSave(){try {Student student = new Student();student.name = etName.getText().toString();student.sex = etSex.getText().toString();student.age = Integer.valueOf(etAge.getText().toString());student.clazz = etClass.getText().toString();Long result = studentDao.save(student);if(result != -1){
// Toast.makeText(getApplication(),"保存数据成功!返回插入行号是["+result+"]",Toast.LENGTH_SHORT).show();showToast("保存数据成功!返回插入行号是["+result+"]");}else{showToast("保存数据失败result["+result+"]");}}catch ( Exception e){e.printStackTrace();}}/**查询数据*/public void selectDataByID(){Long id = etSelectID.getText().toString().equals("") || etSelectID.getText().toString().equals(null) ? null:Long.valueOf(etSelectID.getText().toString());List<Student> data = studentDao.select(id);if(data.equals(null) || data.size() == 0){textView.setText("没有查到数据!");}else {textView.setText(data.toString());}}/**删除数据*/public void deleteDataById(){Long id = etDeleteID.getText().toString().equals("") || etDeleteID.getText().toString().equals(null) ? null : Long.valueOf(etDeleteID.getText().toString());int result = studentDao.delete(id);if(result != 0){showToast("删除数据成功!删除了["+result+"]条记录!");}else{showToast("删除数据失败result["+result+"]");}}/**查询展示图片*/public void selectBitmapMethod(){try {Long id = etSelectID.getText().toString().equals("") || etSelectID.getText().toString().equals(null) ? 1:Long.valueOf(etSelectID.getText().toString());Student data = studentDao.selectBitmapById(id);if(data != null){// 把数据显示到页面etName.setText(data.name);etSex.setText(data.sex);etAge.setText(data.age+"");etClass.setText(data.clazz);//有数据再转if(data.logoHead != null){textView.setText(" ");// 把字节数组 转成位图Bitmap bitmap = BitmapFactory.decodeByteArray(data.logoHead,0,data.logoHead.length);imageView.setImageBitmap(bitmap);}else{textView.setText("没有图片数据!");}}else{textView.setText("没有查到数据!");}}catch (Exception e){e.printStackTrace();showToast("查询失败"+e.getMessage());}}/**更新**/public void updateData(){Long id = etDeleteID.getText().toString().equals("") || etDeleteID.getText().toString().equals(null) ? 1 : Long.valueOf(etDeleteID.getText().toString());Student student = new Student();student.name = etName.getText().toString();student.sex = etSex.getText().toString();student.age = Integer.valueOf(etAge.getText().toString());student.clazz = etClass.getText().toString();int result = studentDao.updateById(student,id);if(result != 0){showToast("修改数据成功!修改了["+result+"]条记录!");}else{textView.setText("没有【"+ id +"】这条记录!");showToast("修改数据失败result["+result+"]");}}public void showToast(String msg) {Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();}//异步弹框public void showToastSync(String msg) {Looper.prepare();Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();Looper.loop();}
}
布局 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity">
<TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="SQLite 简单应用:"android:textSize="24sp"/><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="24sp"android:text="姓名:"/><EditTextandroid:id="@+id/et_name"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"/></LinearLayout><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="24sp"android:text="性别:"/><EditTextandroid:id="@+id/et_sex"android:inputType="text"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"/></LinearLayout><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="24sp"android:text="年龄:"/><EditTextandroid:id="@+id/et_age"android:inputType="number"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"/></LinearLayout><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="24sp"android:text="班级:"/><EditTextandroid:id="@+id/et_class"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="24sp"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/tbn_save"android:layout_weight="1"android:layout_width="0dp"android:layout_height="wrap_content"android:text="保存数据"android:textSize="14sp"/><Buttonandroid:id="@+id/btn_save_bitmap"android:layout_weight="2"android:layout_width="0dp"android:layout_height="wrap_content"android:text="更新数据库版本后保存图片"android:textSize="12sp"/></LinearLayout><!-- 查询--><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:inputType="number"android:id="@+id/et_select_id"android:layout_width="80dp"android:layout_height="wrap_content"android:textSize="24sp"/><Buttonandroid:id="@+id/tbn_select"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="查询数据"android:textSize="12sp"/><Buttonandroid:id="@+id/tbn_select_bitmap"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="根据id查询图片"android:textSize="12sp"/></LinearLayout><!-- 删除--><LinearLayoutandroid:layout_marginLeft="10dp"android:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:inputType="number"android:id="@+id/et_delete_id"android:layout_width="80dp"android:layout_height="wrap_content"android:textSize="24sp"/><Buttonandroid:id="@+id/tbn_delete"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="删除数据"android:textSize="14sp"/><Buttonandroid:id="@+id/btn_update"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="根据id修改"android:textSize="12sp"/></LinearLayout><ScrollViewandroid:background="#ccc"android:layout_width="match_parent"android:layout_height="120dp"><!-- 显示查询结果--><TextViewandroid:layout_marginLeft="10dp"android:textColor="#ff00ff00"android:textSize="22sp"android:id="@+id/tv_data"android:layout_width="match_parent"android:layout_height="wrap_content"/></ScrollView><ImageViewandroid:id="@+id/iv_image"android:layout_width="match_parent"android:layout_height="wrap_content"/></LinearLayout>
源码地址:GitCode - 开发者的代码家园
相关文章:

Android : SQLite 增删改查—简单应用
示例图: 学生实体类 Student.java package com.example.mysqlite.dto;public class Student {public Long id;public String name;public String sex;public int age;public String clazz;public String creatDate;//头像public byte[] logoHead;Overridepublic St…...
【蓝桥杯】马的遍历
马的遍历 题目描述 有一个 n m n \times m nm 的棋盘,在某个点 ( x , y ) (x, y) (x,y) 上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步。 输入格式 输入只有一行四个整数,分别为 n , m , x , y n, m, x, y n,m,x,y。 …...
导入JSON到xmind
写在前面 这只是一个思路,解决大量树状数据,创建xmind低效问题。 函数可以根据你的实际情况优化 1. 转换json格式 function formatToXimd(atd, str) {if (atd) {for (let index 0; index < atd.length; index) {console.log(str - atd[index].…...

DataGrip 2023.2.3(IDE数据库开发)
DataGrip是一款数据库集成开发环境(IDE),用于数据库管理和开发。 DataGrip提供了许多强大的功能,如SQL语句编辑、数据库连接管理、数据导入和导出、数据库比较和同步等等。它支持多种数据库,如MySQL、PostgreSQL、Ora…...

身为 Go 程序员,我为啥更喜欢用 Zig?
Zig 是一种比较新的编程语言,于 2016 年首次推出。Zig 社区将其描述为“一种用于维护稳固的、可优化和可重用软件的通用编程语言”。 看似一句简单的描述,却隐藏着远大的抱负。Zig被看作是可与C语言一较高下的编程语言。此外,Zig 也是一个编…...

Amazon CodeWhisperer 使用体验
文章作者:STRIVE Amazon CodeWhisperer 是最新的代码生成工具,支持多种编程语言,如 java,js,Python 等,能减少开发人员手敲代码时间,提升工作效率。PS:本人是一名 CodeWhisperer 业余爱好者 亚马逊云科技开发者社区为开…...

公众号留言功能怎么申请?
为什么公众号没有留言功能?2018年2月12日,TX新规出台:根据相关规定和平台规则要求,我们暂时调整留言功能开放规则,后续新注册帐号无留言功能。这就意味着2018年2月12日号之后注册的公众号不论个人主体还是组织主体&…...

探索三种生成模型:基于DDPMs、NCSNs和SDEs方法的Diffusion
探索三种生成模型:基于DDPMs、NCSNs和SDEs方法的Diffusion 去噪扩散概率模型(DDPMs)正向过程反向过程 噪声条件得分网络(NCSNs)正向过程初始化训练 NCSNs生成样本 反向过程 随机微分方程(SDEs)原…...
Linux随记(七)
一、欧拉bclinux 21.10安装zabbix-5.0.37.tar.gz (zbx-客户端) #系统环境: BigCloud Enterprise Linux For Euler 21.10 LTS #软件信息: zabbix-5.0.37.tar.gz , pcre-devel-8.44-2.oe1.x86_64.rpm , inst…...
RESTful API,以及如何使用它构建 web 应用程序。
RESTful API是一种基于REST(Representational State Transfer)架构风格的API(Application Programming Interface),它采用HTTP协议中的GET、POST、PUT、DELETE等方法,对资源进行操作。RESTful API的核心思想…...

【华为OD题库-075】拼接URL-Java
题目 题目描述: 给定一个url前缀和url后缀,通过,分割。需要将其连接为一个完整的url。 如果前缀结尾和后缀开头都没有/,需要自动补上/连接符 如果前缀结尾和后缀开头都为/,需要自动去重 约束:不用考虑前后缀URL不合法情况 输入描述: url前缀(一个长度小于…...

【Unity动画】为一个动画片段添加事件Events
动画不管播放到那一帧,我们都可以在这里“埋伏”一个事件(调用一个函数并且给函数传递一个参数,参数在外部设置,甚至传递一个物体)! 嗨,亲爱的Unity小伙伴们!你是否曾想过为你的动画…...

CoDeF视频处理——视频风格转化部署使用与源码解析
一、算法简介与功能 CoDef是作为一种新型的视频表示形式,它包括一个规范内容场,聚合整个视频中的静态内容,以及一个时间变形场,记录了从规范图像(即从规范内容场渲染而成)到每个单独帧的变换过程。针对目标…...
ubuntu server 20.04 备份和恢复 系统 LTS
ubuntu server 20.04 备份和恢复 系统 LTS tar命令系统备份与恢复(还原or新装) 备份系统 cd / su root tar cvpzf backup.tgz --exclude/tmp --exclude/run --exclude/dev --exclude/snap --exclude/proc --exclude/lostfound --exclude/backup.tgz …...

NFC对物联网开发的影响及用途
当谈到NFC对物联网的影响时,不得不提它的几个重要的优势,可能在未来几年影响着物联网的发展方向。 全球智能手机的普及是其中一个重要因素:市面上已有数十亿部支持NFC的智能手机,专家们相信这个数字还会大幅增长。智能手机用户已…...

企业级SQL开发:如何审核发布到生产环境的SQL性能
自从上世纪 70 年代数据库开始普及以来,DBA 们就不停地遭遇各种各样的数据库管理难题,其中最为显著的,可能就是日常的开发任务中,研发人员们对于核心库进行变更带来的一系列风险。由于针对数据库的数据变更是一项非常常见的任务&a…...

linux 手动安装移植 haveged,解决随机数初始化慢的问题
文章目录 1、问题描述2、安装 haveged3、问题解决4、将安装好的文件跟库移植到开发板下 Haveged是一个软件工具,用于生成高质量的熵(Entropy)源,以供计算机系统使用。熵在计算机科学中指的是一种随机性或不可预测性的度量…...

如何使用llm 制作多模态
首先将任何非字符的序列信息使用特殊n个token 编码。 具体编码方法以图像为例子说明: 将固定尺寸图像如256256 的图像分割为1616 的子图像块。 将已知的所有图像数据都分割后进行str将其看做是一个长的字符,而后去重后方式一个词表。 使用特殊1024 个tok…...
k8s(二):Pod
Pod pod 是K8s中最小的可部署单元,用于容纳一个或多个容器。Pod为容器提供了一个共享的环境,包括网络命名空间、存储卷和IP地址。 pod的阶段(phase) Pending: Pod 已被 Kubernetes 系统接受,但有一个或者多个容器尚未创建亦未运行。此阶段包…...
Python 字典详解(dict)
文章目录 1 概述1.1 性质 2 常用方法2.1 以列表返回所有键:keys()2.2 以列表返回所有值:values()2.3 以列表返回所有键值对:items()2.4 返回键对应的值:get()2.5 添加键值对:setdefault()2.6 修改键值对:di…...

Appium+python自动化(十六)- ADB命令
简介 Android 调试桥(adb)是多种用途的工具,该工具可以帮助你你管理设备或模拟器 的状态。 adb ( Android Debug Bridge)是一个通用命令行工具,其允许您与模拟器实例或连接的 Android 设备进行通信。它可为各种设备操作提供便利,如安装和调试…...
线程与协程
1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指:像函数调用/返回一样轻量地完成任务切换。 举例说明: 当你在程序中写一个函数调用: funcA() 然后 funcA 执行完后返回&…...

【第二十一章 SDIO接口(SDIO)】
第二十一章 SDIO接口 目录 第二十一章 SDIO接口(SDIO) 1 SDIO 主要功能 2 SDIO 总线拓扑 3 SDIO 功能描述 3.1 SDIO 适配器 3.2 SDIOAHB 接口 4 卡功能描述 4.1 卡识别模式 4.2 卡复位 4.3 操作电压范围确认 4.4 卡识别过程 4.5 写数据块 4.6 读数据块 4.7 数据流…...

转转集团旗下首家二手多品类循环仓店“超级转转”开业
6月9日,国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解,“超级…...

HBuilderX安装(uni-app和小程序开发)
下载HBuilderX 访问官方网站:https://www.dcloud.io/hbuilderx.html 根据您的操作系统选择合适版本: Windows版(推荐下载标准版) Windows系统安装步骤 运行安装程序: 双击下载的.exe安装文件 如果出现安全提示&…...
C++.OpenGL (10/64)基础光照(Basic Lighting)
基础光照(Basic Lighting) 冯氏光照模型(Phong Lighting Model) #mermaid-svg-GLdskXwWINxNGHso {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-GLdskXwWINxNGHso .error-icon{fill:#552222;}#mermaid-svg-GLd…...

C++ 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
【碎碎念】宝可梦 Mesh GO : 基于MESH网络的口袋妖怪 宝可梦GO游戏自组网系统
目录 游戏说明《宝可梦 Mesh GO》 —— 局域宝可梦探索Pokmon GO 类游戏核心理念应用场景Mesh 特性 宝可梦玩法融合设计游戏构想要素1. 地图探索(基于物理空间 广播范围)2. 野生宝可梦生成与广播3. 对战系统4. 道具与通信5. 延伸玩法 安全性设计 技术选…...

使用LangGraph和LangSmith构建多智能体人工智能系统
现在,通过组合几个较小的子智能体来创建一个强大的人工智能智能体正成为一种趋势。但这也带来了一些挑战,比如减少幻觉、管理对话流程、在测试期间留意智能体的工作方式、允许人工介入以及评估其性能。你需要进行大量的反复试验。 在这篇博客〔原作者&a…...
Go 并发编程基础:通道(Channel)的使用
在 Go 中,Channel 是 Goroutine 之间通信的核心机制。它提供了一个线程安全的通信方式,用于在多个 Goroutine 之间传递数据,从而实现高效的并发编程。 本章将介绍 Channel 的基本概念、用法、缓冲、关闭机制以及 select 的使用。 一、Channel…...