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…...
KubeSphere 容器平台高可用:环境搭建与可视化操作指南
Linux_k8s篇 欢迎来到Linux的世界,看笔记好好学多敲多打,每个人都是大神! 题目:KubeSphere 容器平台高可用:环境搭建与可视化操作指南 版本号: 1.0,0 作者: 老王要学习 日期: 2025.06.05 适用环境: Ubuntu22 文档说…...

XCTF-web-easyupload
试了试php,php7,pht,phtml等,都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接,得到flag...
mongodb源码分析session执行handleRequest命令find过程
mongo/transport/service_state_machine.cpp已经分析startSession创建ASIOSession过程,并且验证connection是否超过限制ASIOSession和connection是循环接受客户端命令,把数据流转换成Message,状态转变流程是:State::Created 》 St…...

YSYX学习记录(八)
C语言,练习0: 先创建一个文件夹,我用的是物理机: 安装build-essential 练习1: 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件,随机修改或删除一部分,之后…...

NLP学习路线图(二十三):长短期记忆网络(LSTM)
在自然语言处理(NLP)领域,我们时刻面临着处理序列数据的核心挑战。无论是理解句子的结构、分析文本的情感,还是实现语言的翻译,都需要模型能够捕捉词语之间依时序产生的复杂依赖关系。传统的神经网络结构在处理这种序列依赖时显得力不从心,而循环神经网络(RNN) 曾被视为…...
【HTTP三个基础问题】
面试官您好!HTTP是超文本传输协议,是互联网上客户端和服务器之间传输超文本数据(比如文字、图片、音频、视频等)的核心协议,当前互联网应用最广泛的版本是HTTP1.1,它基于经典的C/S模型,也就是客…...
C++八股 —— 单例模式
文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全(Thread Safety) 线程安全是指在多线程环境下,某个函数、类或代码片段能够被多个线程同时调用时,仍能保证数据的一致性和逻辑的正确性…...
LeetCode - 199. 二叉树的右视图
题目 199. 二叉树的右视图 - 力扣(LeetCode) 思路 右视图是指从树的右侧看,对于每一层,只能看到该层最右边的节点。实现思路是: 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...

【分享】推荐一些办公小工具
1、PDF 在线转换 https://smallpdf.com/cn/pdf-tools 推荐理由:大部分的转换软件需要收费,要么功能不齐全,而开会员又用不了几次浪费钱,借用别人的又不安全。 这个网站它不需要登录或下载安装。而且提供的免费功能就能满足日常…...

热门Chrome扩展程序存在明文传输风险,用户隐私安全受威胁
赛门铁克威胁猎手团队最新报告披露,数款拥有数百万活跃用户的Chrome扩展程序正在通过未加密的HTTP连接静默泄露用户敏感数据,严重威胁用户隐私安全。 知名扩展程序存在明文传输风险 尽管宣称提供安全浏览、数据分析或便捷界面等功能,但SEMR…...