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

图书管理系统(JDBC)

AdminUser是管理员类

NormalUser是用户类

AddOperation是增加图书类

BorrowOperation是借书类

DelOperation是删除图书类

ExitOperation是退出类

FindOperation是查找图书类

IOPeration是接口

ReturnOperation是还书类

ShowOperation是显示所有图书类

注意:我的数据库有个cnm数据库,如果你没有的话,需要先创建一个cnm数据库

sql建表语句:

drop table if exists book;
create table book
(	id			   	 bigint  auto_increment,name              varchar(255), author            varchar(255),price             int,type              varchar(255),isBorrowed        varchar(255),primary key (id)
);insert book(name,author,price,type,isBorrowed) values('西游记','吴承恩',35,'小说','未借阅');
insert book(name,author,price,type,isBorrowed) values('活着','余华',40,'文学','未借阅');
commit;
select * from book;

Book类

package book;public class Book {private String name;//书名private String author;//作者private int price;//价格private String type;//类型private boolean isBorrowed;//是否被借出,初始值是false,在构造方法中不用写public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}public String getType() {return type;}public void setType(String type) {this.type = type;}public boolean isBorrowed() {return isBorrowed;}public void setBorrowed(boolean borrowed) {isBorrowed = borrowed;}public Book(String name, String author, int price, String type) {this.name = name;this.author = author;this.price = price;this.type = type;}@Overridepublic String toString() {return "Book{" +"name:" + name +",  author:" + author +",  price:" + price +",  type=:" + type +",  isBorrowed:" +(isBorrowed==true?"  已借出":"  未借出") +'}';}
}

BookList类

package book;public class BookList {private static final int DEFAULT_SIZE=10;//该常量定义一个书架有多少本书private  Book[] books=new  Book[DEFAULT_SIZE];private int usedSize;//记录下当前book数组中有几本书public int getUsedSize() {return usedSize;}public void setUsedSize(int usedSize) {this.usedSize = usedSize;}}

User类

package user;import book.BookList;
import opera.IOPeration;public abstract class User {//抽象类protected String name;//名字.这边的protect代表的是名字的权限。如果是private,它只能在同一个包的同一类使用。就不能让AdminUser类继承了。写public的话//权限太大了,不是很好。protected IOPeration[] ioPerations;public User(String name) {//构造方法this.name = name;}public abstract int menu();//抽象方法,打印菜单,因为有了choice返回值int类型,所以void改成intpublic void doWork(int choice, BookList bookList){//通过选择的操作,去选择执行数组下的哪个操作this.ioPerations[choice].work(bookList);}
}

AdminUser类

package user;import opera.*;import java.util.Scanner;public class AdminUser extends User{public AdminUser(String name) {super(name);this.ioPerations=new IOPeration[]{new ExitOperation(),new FindOperation(),new AddOperation(),new DelOperation(),new ShowOperation()};System.out.println("欢迎管理员:"+name);}@Overridepublic int menu() {//因为返回值choice是int类型的System.out.println("____________________________________");System.out.println("1.查找图书");System.out.println("2.新增图书");System.out.println("3.删除图书");System.out.println("4.显示图书");System.out.println("0.退出系统");System.out.println("请选择你需要的功能:");Scanner scanner=new Scanner(System.in);int choice=scanner.nextInt();return choice;}}

NormalUser类

package user;import opera.*;import java.util.Scanner;public class NormalUser extends User {public NormalUser(String name) {super(name);this.ioPerations = new IOPeration[]{//引用,这边用super也可以,因为这里没有同名的,不需要做区分。用this最好new ExitOperation(),new FindOperation(),new BorrowOperation(),new ReturnOperation()};System.out.println("欢迎用户:"+name);}@Overridepublic int menu() {System.out.println("_________________");System.out.println("1.查找图书!");System.out.println("2.借阅图书!");System.out.println("3.归还图书!");System.out.println("0.退出系统!");Scanner scanner = new Scanner(System.in);int choice = scanner.nextInt();return choice;}}

IOPeration接口

package opera;import book.BookList;public interface IOPeration {//创建接口void work(BookList bookList);//抽象方法//功能主要是针对图书的,也就是针对书架。
}

AddOperation类

package opera;import book.Book;
import book.BookList;import java.sql.*;
import java.util.Scanner;public class AddOperation implements IOPeration {public void work(BookList bookList) {System.out.println("新增图书!");Scanner scanner = new Scanner(System.in);System.out.println("请输入新增图书名字:");String name = scanner.nextLine();System.out.println("请输入新增图书作者:");String author = scanner.nextLine();System.out.println("请输入价格");int price = scanner.nextInt();//吸收回车符号scanner.nextLine();System.out.println("请输入图书类型:");String type = scanner.nextLine();//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book where name='"+name+"'";rs = stmt.executeQuery(sql);if(!rs.next()) {String s = "insert into book avalues('"+name+"','"+author+"','"+price+"','"+type+"','未借阅')";int x= stmt.executeUpdate(s);if(x>0)System.out.println("新增图书成功!");elseSystem.out.println("新增图书失败");}else{System.out.println("已经有这本书了");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}}

DelOperation类

package opera;import book.Book;
import book.BookList;import java.sql.*;
import java.util.Scanner;public class DelOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("删除图书!");System.out.println("请输入要删除图书的名称");Scanner scanner=new Scanner(System.in);String name=scanner.nextLine();//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book where name='"+name+"'";rs = stmt.executeQuery(sql);if(rs.next()) {String s = "delete from book where name='"+name+"'";int x = stmt.executeUpdate(s);if(x>0)System.out.println("删除成功!");elseSystem.out.println("删除失败!");}else{System.out.println("没有这本书");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}}

FindOperation类

package opera;import book.Book;
import book.BookList;import java.sql.*;
import java.util.Scanner;public class FindOperation implements IOPeration{//继承@Overridepublic void work(BookList bookList) {//重写IOPeration类中的work方法System.out.println("查找图书!");System.out.println("请输入要查找的图书名字");Scanner scanner=new Scanner(System.in);String name=scanner.nextLine();//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book where name='"+name+"'";rs = stmt.executeQuery(sql);if(rs.next()) {while (true) {String s1 = rs.getString("name");String s2 = rs.getString("author");int s3 = rs.getInt("price");String s4 = rs.getString("type");String s5 = rs.getString("isBorrowed");System.out.print("name: " + s1);System.out.print(",author:" + s2);System.out.print(",price:" + s3);System.out.print(",type:" + s4);System.out.print(",isBorrowed:" + s5);System.out.println();if(!rs.next())break;}}else{System.out.println("没有这本书");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}}

ShowOperation类

package opera;import book.BookList;import java.sql.*;public class ShowOperation implements IOPeration{@Overridepublic void work(BookList bookList) {//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book ";rs = stmt.executeQuery(sql);if(rs.next()) {while (true) {String s1 = rs.getString("name");String s2 = rs.getString("author");int s3 = rs.getInt("price");String s4 = rs.getString("type");String s5 = rs.getString("isBorrowed");System.out.print("name: " + s1);System.out.print(",author:" + s2);System.out.print(",price:" + s3);System.out.print(",type:" + s4);System.out.print(",isBorrowed:" + s5);System.out.println();if(!rs.next())break;}}else{System.out.println("没有这本书");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}
}

BorrowOperation类

package opera;import book.Book;
import book.BookList;import java.sql.*;
import java.util.Scanner;public class BorrowOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("借阅图书!");System.out.println("请输入要借阅的图书名字:");Scanner scanner=new Scanner(System.in);String name=scanner.nextLine();//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book where name='"+name+"'";rs = stmt.executeQuery(sql);if(rs.next()) {String s1 = "select isBorrowed from book where name='"+name+"'";rs = stmt.executeQuery(s1);if(rs.next()){String str = rs.getString("isBorrowed");if(str.equals("未借阅")) {String s2 = "update book set isBorrowed='已借阅' where name='" + name + "'";int x = stmt.executeUpdate(s2);if (x > 0)System.out.println("借阅成功!");elseSystem.out.println("借阅失败");}}}else{System.out.println("没有这本书");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}
}

ReturnOperation类

package opera;import book.Book;
import book.BookList;import java.sql.*;
import java.util.Scanner;public class ReturnOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("归还图书!");System.out.println("请输入要归还的图书名字:");Scanner scanner=new Scanner(System.in);String name=scanner.nextLine();//添加到数据库//定义3个变量Connection conn = null;Statement stmt = null;ResultSet rs = null;try {//1.注册驱动Class.forName("com.mysql.cj.jdbc.Driver");//2.获取连接conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cnm", "root", "123456");//3.获取数据库操作对象(执行sql语句的对象)stmt = conn.createStatement();//4.执行sql语句String sql = "select * from book where name='"+name+"'";rs = stmt.executeQuery(sql);if(rs.next()) {String s1 = "select isBorrowed from book where name='"+name+"'";rs = stmt.executeQuery(s1);if(rs.next()){String str = rs.getString("isBorrowed");if(str.equals("已借阅")) {String s2 = "update book set isBorrowed='未借阅' where name='" + name + "'";int x = stmt.executeUpdate(s2);if (x > 0)System.out.println("归还成功!");elseSystem.out.println("归还失败");}}}else{System.out.println("没有这本书");}}catch (Exception e) {e.printStackTrace();} finally {//6.释放资源if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}
}

ExitOperation类

package opera;import book.BookList;public class ExitOperation implements IOPeration{@Overridepublic void work(BookList bookList) {System.out.println("退出系统!");System.exit(0);//退出系统。0代表正常退出}
}

Main类

import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;import java.util.Scanner;public class Main {//登录public static User login() {System.out.println("请输入你的姓名:");Scanner scanner = new Scanner(System.in);String name = scanner.nextLine();System.out.println("请选择你的身份:1->管理员 0->普通用户");int choice = scanner.nextInt();if (choice == 1) {//说明是管理员//由于有返回值,所以我们的方法返回值就不能写void了。但是我们也无法确定返回值是什么,可能是管理员,可能是用户。所以,用向上转型,写User.return new AdminUser(name);//返回实例化一个管理员对象} else {return new NormalUser(name);//返回实例化一个用户对象}}public static void main(String[] args) {User user = login();//执行上面的login方法BookList bookList = new BookList();while (true) {int choice = user.menu();//实现打印菜单user.doWork(choice, bookList);}}
}

相关文章:

图书管理系统(JDBC)

AdminUser是管理员类 NormalUser是用户类 AddOperation是增加图书类 BorrowOperation是借书类 DelOperation是删除图书类 ExitOperation是退出类 FindOperation是查找图书类 IOPeration是接口 ReturnOperation是还书类 ShowOperation是显示所有图书类 注意&#xff1a…...

模板初阶及STL简介

目录 一.模板初阶 1.泛型函数 2.函数模板 1.函数模板概念 2.函数模板使用格式 3.函数模板的原理 4.函数模板的实例化 5.模板参数的匹配原则 3.类模板 1.类模板的定义格式 2.类模板的实例化 二.STL简介 1.什么是STL 2.STL的版本 3.STL的六大组件 4.如何学习STL …...

UE5 不同的编译模式下,module的组织形式

由于最近在琢磨UE5.4这个引擎,在学习过程中,碰到了一些非常有意思的事情,我在尝试把之前写的一些底层库搬到UE里面,比如底层库,网络库等等,我通过建立module,将这些库用源代码的方式整合进了UE5…...

【ms-swift 大模型微调实战】

安装环境 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simplepip install modelscope vllm ‘ms-swift[llm]’ -U 下载模型 modelscope download --model Qwen/Qwen2.5-7B-Instruct --local_dir ./Qwen2.5-7B-Instruct 微调 实验环境:…...

Linux:网络基础

计算机是人的工具,人需要协作,于是有了网络 专用服务器->专用计算机 局域网:随着计算机的数量增加,通过交换机和路由器连接计算机 广域网:将远隔千里的计算机都连在一起 协议 协议就是约定俗成 计算机之间用光信号…...

mysql 的内连接、左连接、右连接有什么区别?

在MySQL中,内连接、左连接和右连接是三种常见的连接类型,它们用于通过共享一个或多个字段的值,将两个或多个表组合在一起进行查询。以下是这三种连接类型的详细区别: 一、内连接(INNER JOIN) 定义&#x…...

update-alternatives(选择工具)

0 Preface/foreword 1 update-alternatives介绍 1.1 选项和用法 1.2 install用法 update-alternatives --install <link> <name> <path> <priority> [--slave <link> <name> <path>] link&#xff1a;符号链接&#xff08;软链…...

php解密,sg11解密-sg15解密 如何由sourceGuardian11-sourceGuardian15加密(sg11加密~sg15加密)的源码

sg11加密~sg11加密的PHP文件运行需安装SG11加密-SG15加密组件使用、支持WINDOW及LINUX各版本 sg11解密(SourceGuardian)-sg15解密(SourceGuardian)&#xff0c;号称目前最安全的组件加密已可以解密&#xff0c;解密率99.9%&#xff0c;基本可以直接使用&#xff0c;代码特征是…...

b站小土堆PyTorch视频学习笔记(二)

Dataloader:提供不同类型的数据集&#xff1b;为后面的网络提供不同的数据形式 Dataset&#xff1a;提供一种方式去获取数据及其label&#xff08;标签&#xff09; 主要实现以下两个功能&#xff1a; {如何获取每一个数据及其lable&#xff1b;告诉我们总共有多少数据} fr…...

Linux的压缩及其解压命令

1、zip文件 压缩 zip linux.zip linux 解压 unzip linux.zip 2、gz文件 压缩 gzip 1.tar 解压 gzip -d 1.tar.gz 3、tar文件(tar可打/解包&#xff0c;压缩/解压文件) 打包 tar -cf 1.rar test 解包 tar -xf 1.tar 解压gz并解包 tar -xjvf archive_name.tar.bz2&#…...

GXYCTF2019:gakki

把题目给的附件解压后给了张图片&#xff0c;顺带着瞟一眼属性&#xff0c;没有值得注意的 binwalk检测一手&#xff0c;看见有个rar压缩包 提取出来的压缩包是有密码的&#xff0c;但是题目并没有给出获取密码的途径&#xff0c;所以先爆破试试&#xff0c;用最常用的四位数爆…...

顺序表(C 语言)

目录 一、线性表二、顺序表1. 静态顺序表2. 动态顺序表2.1 动态顺序表的实现分析2.2 动态顺序表的实现2.3 动态顺序表存在的问题 三、与数组有关的面试题1. 移除元素2. 删除有序数组中的重复项 一、线性表 线性表&#xff08;linear list&#xff09;是n个具有相同特性的数据元…...

一:时序数据库-Influx应用

目录 0、版本号 1、登录页面 2、账号基本信息 3、数据库案例 4、可视化 5、java案例 0、版本号 InfluxDB v2.4.0 1、登录页面 http://127.0.0.1:8086/signin 账号&#xff1a;自己账号 密码&#xff1a;自己密码 2、账号基本信息 查看用户id和组织id&#xff01;&…...

Word文档丢失抢救方法:15 个 Word 文档恢复工具

MS Word 文档恢复的重要性 对于严重依赖 Microsoft Word 创建和编辑文档的个人和企业来说&#xff0c;MS Word 文档恢复是一个至关重要的方面。 文件损坏、系统崩溃和其他意外事件可能会导致 Word 文档中存储的重要数据丢失。 及时恢复这些文档有助于节省时间、精力和资源。 本…...

关于自动驾驶等级相关知识

本文主要介绍自动驾驶等级的一下知识&#xff0c;在介绍之前&#xff0c;首先要介绍一些基本知识&#xff0c;然后介绍自动驾驶不同等级 1、自动驾驶相关知识 监控和判断&#xff08;OEDA&#xff09;&#xff1a;指对车辆周围的物体和事件进行检测和感知&#xff0c;并给出应…...

Java中跳转结构

在Java中&#xff0c;跳转结构用于控制程序的执行流程。 2.4.1 break 用途: 用于终止当前循环&#xff08;for、while、do-while&#xff09;或switch语句。 public class BreakExample {public static void main(String[] args) {for (int i 0; i < 10; i) {if (i 5) …...

CNN-Attention分类预测 | Matlab实现多特征分类预测

CNN-Attention分类预测 | Matlab实现多特征分类预测 目录 CNN-Attention分类预测 | Matlab实现多特征分类预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.Matlab实现CNN-Attention卷积神经网络融合注意力机制多特征分类预测&#xff0c;运行环境Matlab2023b及以上…...

[java][基础]JSP

目标&#xff1a; 理解 JSP 及 JSP 原理 能在 JSP中使用 EL表达式 和 JSTL标签 理解 MVC模式 和 三层架构 能完成品牌数据的增删改查功能 1&#xff0c;JSP 概述 JSP&#xff08;全称&#xff1a;Java Server Pages&#xff09;&#xff1a;Java 服务端页面。是一种动态的…...

《测绘学报》

《测绘学报》 办刊宗旨&#xff1a;尊重科学、弘扬学术、追求卓越、求实创新。60多年来&#xff0c;《测绘学报》作为承载着测绘地理信息科学技术和科研成果的载体&#xff0c;作为测绘地理信息行业人才培养和学术交流的阵地&#xff0c;坚持把学术论文的质量放在期刊工作的重要…...

代码随想录之链表刷题总结

目录 1.链表理论基础 2.移除链表元素 3.设计链表 4.翻转链表 5.两两交换链表中的节点 6.删除链表中的第N个节点 7.链表相交 8.环形链表 1.链表理论基础 链表是一种通过指针串联在一起的线性结构&#xff0c;每一个节点由两部分组成&#xff0c;一个是数据域一个是指针域…...

Python爬虫的“京东大冒险”:揭秘商品类目信息

开篇&#xff1a;欢迎来到Python的奇幻森林 在这个数据驱动的时代&#xff0c;我们就像一群探险家&#xff0c;穿梭在数字的森林中&#xff0c;寻找着隐藏的宝藏——商品类目信息。今天&#xff0c;我们将带领你一起&#xff0c;用Python这把锋利的剑&#xff0c;深入京东的神…...

双目视觉标定——1原理与实践

0 前言 双目视觉定位是目前机器&#xff08;机器人&#xff09;等领域中使用得非常广泛的视觉定位技术&#xff0c;双目视觉是模拟人的视觉系统利用两个不同位置的摄像头的视差来确定物体的位置。由于有需要采集两个摄像头的图像共同参与计算&#xff0c;所以双目相机装配要求…...

【设计模式系列】代理模式(八)

一、什么是代理模式 代理模式&#xff08;Proxy Pattern&#xff09;是一种结构型设计模式&#xff0c;它为其他对象提供一种代理以控制对这个对象的访问。代理模式在不直接访问实际对象的情况下&#xff0c;提供了对目标对象的间接访问。通过引入一个代理对象来间接操作实际对…...

微服务架构设计的初次尝试——基于以太坊智能合约 + NestJS 微服务的游戏社区与任务市场系统:架构设计

TMDOG微服务架构设计的初次尝试——基于以太坊智能合约 NestJS 微服务的游戏社区与任务市场系统&#xff1a;架构设计 一、开发背景及目的 随着区块链技术的蓬勃发展以及去中心化概念的兴起&#xff0c;越来越多的开发者开始探索如何将区块链应用到实际业务场景中&#xff0…...

“北斗+实景三维”,助力全域社会治理

在国家治理体系和治理能力现代化的大背景下&#xff0c;全域社会治理成为提升国家治理效能的关键。“北斗实景三维”技术组合&#xff0c;为全域社会治理提供了新的技术支撑和解决方案。本文将探讨这一技术如何助力全域社会治理&#xff0c;以及其在实际应用中的潜力和挑战。 …...

#渗透测试#SRC漏洞挖掘# 信息收集-常见端口及谷歌语法

免责声明 本教程仅为合法的教学目的而准备&#xff0c;严禁用于任何形式的违法犯罪活动及其他商业行为&#xff0c;在使用本教程前&#xff0c;您应确保该行为符合当地的法律法规&#xff0c;继续阅读即表示您需自行承担所有操作的后果&#xff0c;如有异议&#xff0c;请立即停…...

如何使用java雪花算法在分布式环境中生成唯一ID?

引言 在现代分布式系统中,生成唯一标识符(ID)是一个常见的需求。传统的自增ID在分布式环境中会导致冲突,因此需要一种能够在分布式系统中生成全局唯一ID的算法。 雪花算法(Snowflake)就是为了解决这个问题而提出的一种高效的ID生成算法。本文将详细介绍雪花算法的原理、…...

【php常用公共函数】php获取指定时间段相差几小时,几分钟,几秒

实现代码 <?php function diffTime($datetime1, $datetime2) {// 确保 $datetime1 总是小于或等于 $datetime2if (strtotime($datetime1) > strtotime($datetime2)) {$tmp $datetime2;$datetime2 $datetime1;$datetime1 $tmp;}// 转换为时间戳$timestamp1 strtotim…...

图文深入介绍Oracle DB link(一)

1. 引言&#xff1a; 本文图文深入介绍Oracle DB link&#xff0c;先介绍基本概念。 2.DB link的定义 数据库链接&#xff08;Database Link&#xff0c;简称 DB Link&#xff09;是 Oracle 数据库中的一个重要功能。它是一种在一个 Oracle 数据库实例中访问另一个 Oracle 数…...

Uniswap/v2-core使用及其交易流程

Uniswap是一个开源的去中心化的交易所&#xff0c;在github上面有以下重要仓库&#xff1a; uniswap-v2-core&#xff1a; 币对池pair的核心智能合约。这个repository包含了Uniswap的币对池pair的所有核心逻辑&#xff0c;增加流动性、减少流动性等。uniswap-v2-periphery&…...