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

Python 3 教程第33篇(MySQL - mysql-connector 驱动)

Python MySQL - mysql-connector 驱动

MySQL 是最流行的关系型数据库管理系统,如果你不熟悉 MySQL,可以阅读我们的 MySQL 教程。
本章节我们为大家介绍使用 mysql-connector 来连接使用 MySQL, mysql-connector 是 MySQL 官方提供的驱动器。

我们可以使用 pip 命令来安装 mysql-connector:

python -m pip install mysql-connector

使用以下代码测试 mysql-connector 是否安装成功:

demo_mysql_test.py:

import mysql.connector

执行以上代码,如果没有产生错误,表明安装成功。
注意:如果你的 MySQL 是 8.0 版本,密码插件验证方式发生了变化,早期版本为 mysql_native_password,8.0 版本为 caching_sha2_password,所以需要做些改变:

先修改 my.ini 配置:

[mysqld]
default_authentication_plugin=mysql_native_password

然后在 mysql 下执行以下命令来修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';

更多内容可以参考:Python MySQL8.0 链接问题。


创建数据库连接

可以使用以下代码来连接数据库:
demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",       # 数据库主机地址user="yourusername",    # 数据库用户名passwd="yourpassword"   # 数据库密码
)
print(mydb)

创建数据库
创建数据库使用 “CREATE DATABASE” 语句,以下创建一个名为 runoob_db 的数据库:

demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE DATABASE runoob_db")

创建数据库前我们也可以使用 “SHOW DATABASES” 语句来查看数据库是否存在:
demo_mysql_test.py:
输出所有数据库列表:

import mysql.connectormydb = mysql.connector.connect(host="localhost",user="root",passwd="123456"
)
mycursor = mydb.cursor()
mycursor.execute("SHOW DATABASES")
for x in mycursor:print(x)

或者我们可以直接连接数据库,如果数据库不存在,会输出错误信息:
demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)

创建数据表

创建数据表使用 “CREATE TABLE” 语句,创建数据表前,需要确保数据库已存在,以下创建一个名为 sites 的数据表:

demo_mysql_test.py:
import mysql.connectormydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE TABLE sites (name VARCHAR(255), url VARCHAR(255))")

执行成功后,我们可以看到数据库创建的数据表 sites,字段为 name 和 url。
在这里插入图片描述

我们也可以使用 “SHOW TABLES” 语句来查看数据表是否已存在:
demo_mysql_test.py:

import mysql.connector 
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SHOW TABLES")
for x in mycursor:print(x)

主键设置
创建表的时候我们一般都会设置一个主键(PRIMARY KEY),我们可以使用 “INT AUTO_INCREMENT PRIMARY KEY” 语句来创建一个主键,主键起始值为 1,逐步递增。
如果我们的表已经创建,我们需要使用 ALTER TABLE 来给表添加主键:
demo_mysql_test.py:
给 sites 表添加主键。

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("ALTER TABLE sites ADD COLUMN id INT AUTO_INCREMENT PRIMARY KEY")

如果你还未创建 sites 表,可以直接使用以下代码创建。
demo_mysql_test.py:
给表创建主键。

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("CREATE TABLE sites (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), url VARCHAR(255))")

插入数据

插入数据使用 “INSERT INTO” 语句:
demo_mysql_test.py:
向 sites 表插入一条记录。

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "INSERT INTO sites (name, url) VALUES (%s, %s)"
val = ("RUNOOB", "https://www.runoob.com")
mycursor.execute(sql, val)
mydb.commit()    # 数据表内容有更新,必须使用到该语句
print(mycursor.rowcount, "记录插入成功。")

执行代码,输出结果为:

1 记录插入成功

批量插入
批量插入使用 executemany() 方法,该方法的第二个参数是一个元组列表,包含了我们要插入的数据:
demo_mysql_test.py:
向 sites 表插入多条记录。

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "INSERT INTO sites (name, url) VALUES (%s, %s)"
val = [('Google', 'https://www.google.com'),('Github', 'https://www.github.com'),('Taobao', 'https://www.taobao.com'),('stackoverflow', 'https://www.stackoverflow.com/')
]
mycursor.executemany(sql, val)
mydb.commit()    # 数据表内容有更新,必须使用到该语句
print(mycursor.rowcount, "记录插入成功。")

执行代码,输出结果为:

4 记录插入成功。

执行以上代码后,我们可以看看数据表的记录:
在这里插入图片描述

如果我们想在数据记录插入后,获取该记录的 ID ,可以使用以下代码:
demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "INSERT INTO sites (name, url) VALUES (%s, %s)"
val = ("Zhihu", "https://www.zhihu.com")
mycursor.execute(sql, val)
mydb.commit()
print("1 条记录已插入, ID:", mycursor.lastrowid)

执行代码,输出结果为:

1 条记录已插入, ID: 6

查询数据

查询数据使用 SELECT 语句:
demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM sites")
myresult = mycursor.fetchall()     # fetchall() 获取所有记录
for x in myresult:print(x)

执行代码,输出结果为:

(1, 'RUNOOB', 'https://www.runoob.com')
(2, 'Google', 'https://www.google.com')
(3, 'Github', 'https://www.github.com')
(4, 'Taobao', 'https://www.taobao.com')
(5, 'stackoverflow', 'https://www.stackoverflow.com/')
(6, 'Zhihu', 'https://www.zhihu.com')

也可以读取指定的字段数据:

demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT name, url FROM sites")
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

('RUNOOB', 'https://www.runoob.com')
('Google', 'https://www.google.com')
('Github', 'https://www.github.com')
('Taobao', 'https://www.taobao.com')
('stackoverflow', 'https://www.stackoverflow.com/')
('Zhihu', 'https://www.zhihu.com')

如果我们只想读取一条数据,可以使用 fetchone() 方法:
demo_mysql_test.py:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM sites")
myresult = mycursor.fetchone()
print(myresult)

执行代码,输出结果为:

(1, 'RUNOOB', 'https://www.runoob.com')

where 条件语句
如果我们要读取指定条件的数据,可以使用 where 语句:
demo_mysql_test.py
读取 name 字段为 RUNOOB 的记录:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM sites WHERE name ='RUNOOB'"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(1, 'RUNOOB', 'https://www.runoob.com')

也可以使用通配符 %:
demo_mysql_test.py

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM sites WHERE url LIKE '%oo%'"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(1, 'RUNOOB', 'https://www.runoob.com')
(2, 'Google', 'https://www.google.com')

为了防止数据库查询发生 SQL 注入的攻击,我们可以使用 %s 占位符来转义查询的条件:
demo_mysql_test.py

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM sites WHERE name = %s"
na = ("RUNOOB", )
mycursor.execute(sql, na)
myresult = mycursor.fetchall()
for x in myresult:print(x)

排序
查询结果排序可以使用 ORDER BY 语句,默认的排序方式为升序,关键字为 ASC,如果要设置降序排序,可以设置关键字 DESC。
demo_mysql_test.py
按 name 字段字母的升序排序:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM sites ORDER BY name"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(3, 'Github', 'https://www.github.com')
(2, 'Google', 'https://www.google.com')
(1, 'RUNOOB', 'https://www.runoob.com')
(5, 'stackoverflow', 'https://www.stackoverflow.com/')
(4, 'Taobao', 'https://www.taobao.com')
(6, 'Zhihu', 'https://www.zhihu.com')

降序排序实例:

demo_mysql_test.py
按 name 字段字母的降序排序:

import mysql.connectormydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "SELECT * FROM sites ORDER BY name DESC"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(6, 'Zhihu', 'https://www.zhihu.com')
(4, 'Taobao', 'https://www.taobao.com')
(5, 'stackoverflow', 'https://www.stackoverflow.com/')
(1, 'RUNOOB', 'https://www.runoob.com')
(2, 'Google', 'https://www.google.com')
(3, 'Github', 'https://www.github.com')

Limit
如果我们要设置查询的数据量,可以通过 “LIMIT” 语句来指定
demo_mysql_test.py
读取前 3 条记录:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM sites LIMIT 3")
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(1, 'RUNOOB', 'https://www.runoob.com')
(2, 'Google', 'https://www.google.com')
(3, 'Github', 'https://www.github.com')

也可以指定起始位置,使用的关键字是 OFFSET:
demo_mysql_test.py
从第二条开始读取前 3 条记录:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM sites LIMIT 3 OFFSET 1")  # 0 为 第一条,1 为第二条,以此类推
myresult = mycursor.fetchall()
for x in myresult:print(x)

执行代码,输出结果为:

(2, 'Google', 'https://www.google.com')
(3, 'Github', 'https://www.github.com')
(4, 'Taobao', 'https://www.taobao.com')

删除记录

删除记录使用 “DELETE FROM” 语句:
demo_mysql_test.py
删除 name 为 stackoverflow 的记录:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "DELETE FROM sites WHERE name = 'stackoverflow'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, " 条记录删除")

执行代码,输出结果为:

1  条记录删除

注意:要慎重使用删除语句,删除语句要确保指定了 WHERE 条件语句,否则会导致整表数据被删除。
为了防止数据库查询发生 SQL 注入的攻击,我们可以使用 %s 占位符来转义删除语句的条件:
demo_mysql_test.py

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "DELETE FROM sites WHERE name = %s"
na = ("stackoverflow", )
mycursor.execute(sql, na)
mydb.commit()
print(mycursor.rowcount, " 条记录删除")

执行代码,输出结果为:

1  条记录删除

更新表数据

数据表更新使用 “UPDATE” 语句:
demo_mysql_test.py
将 name 为 Zhihu 的字段数据改为 ZH:

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "UPDATE sites SET name = 'ZH' WHERE name = 'Zhihu'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, " 条记录被修改")

执行代码,输出结果为:

1  条记录被修改

注意:UPDATE 语句要确保指定了 WHERE 条件语句,否则会导致整表数据被更新。
为了防止数据库查询发生 SQL 注入的攻击,我们可以使用 %s 占位符来转义更新语句的条件:
demo_mysql_test.py

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "UPDATE sites SET name = %s WHERE name = %s"
val = ("Zhihu", "ZH")
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, " 条记录被修改")

执行代码,输出结果为:

1  条记录被修改

删除表
删除表使用 “DROP TABLE” 语句, IF EXISTS 关键字是用于判断表是否存在,只有在存在的情况才删除:
demo_mysql_test.py

import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="root",passwd="123456",database="runoob_db"
)
mycursor = mydb.cursor()
sql = "DROP TABLE IF EXISTS sites"  # 删除数据表 sites
mycursor.execute(sql)

相关文章:

Python 3 教程第33篇(MySQL - mysql-connector 驱动)

Python MySQL - mysql-connector 驱动 MySQL 是最流行的关系型数据库管理系统,如果你不熟悉 MySQL,可以阅读我们的 MySQL 教程。 本章节我们为大家介绍使用 mysql-connector 来连接使用 MySQL, mysql-connector 是 MySQL 官方提供的驱动器。…...

23种设计模式之外观模式

目录 1. 简介2. 代码2.1 SelectFoodService (选择食品)2.2 PayService (支付服务)2.3 TakeService (制作服务)2.4 OrderService (下单服务)2.5 Food (食品)2.6 TackingSystem (外观类)2.7 Test (测试类) 3. 优缺点3. 总结 1. 简介…...

GateWay使用手册

好的&#xff0c;下面是优化后的版本。为了提高可读性和规范性&#xff0c;我对内容进行了结构化、简化了部分代码&#xff0c;同时增加了注释说明&#xff0c;便于理解。 1. 引入依赖 在 pom.xml 中添加以下依赖&#xff1a; <dependencies><!-- Spring Cloud Gate…...

MySQL1.0

1.数据库的三大范式 范式是为了使数据库设计更加合理&#xff0c;规范&#xff0c;减少数据冗余和数据不一致等问题指定的一系列规则。 第一范式&#xff1a;第一范式要求数据表中的每一列都是不可分割的原子数据项。例如&#xff1a;有一个学生信息表&#xff0c;包含 “学生…...

IDEA使用HotSwapHelper进行热部署

目录 前言JDK1.8特殊准备DECVM安装插件安装与配置参考文档相关下载 前言 碰到了一个项目&#xff0c;用jrebel启动项目时一直报错&#xff0c;不用jrebel时又没问题&#xff0c;找不到原因&#xff0c;又不想放弃热部署功能 因此思考能否通过其他方式进行热部署&#xff0c;找…...

简单web项目自定义部署Dockerfile

本意就是弄清楚如何做web自定义项目的镜像。 基础镜像是java:8u261-jdk&#xff0c;其中java路径为/opt/java webdemo1.0.0.1-SNAPSHOT.jar文件里面已经包含了lib文件。 可以设置PATH也可以不设置&#xff0c;但是建议设置JAVA_HOME FROM swr.cn-north-4.myhuaweicloud.com…...

基础Web安全|SQL注入

基础Web安全 URI Uniform Resource Identifier&#xff0c;统一资源标识符&#xff0c;用来唯一的标识一个资源。 URL Uniform Resource Locator&#xff0c;统一资源定位器&#xff0c;一种具体的URI&#xff0c;可以标识一个资源&#xff0c;并且指明了如何定位这个资源…...

SpringBoot -拦截器Interceptor、过滤器 Filter 及设置

Spring Boot拦截器&#xff08;Interceptor&#xff09;的概念 - 在Spring Boot中&#xff0c;拦截器是一种AOP的实现方式。它主要用于<font style"color:#DF2A3F;">拦截请求</font>&#xff0c;在请求处理之前和之后执行特定的代码逻辑。与过滤器不同的…...

C++小问题

怎么分辨const修饰的是谁 是限定谁不能被改变的&#xff1f; 在C中&#xff0c;const关键字的用途和位置非常关键&#xff0c;它决定了谁不能被修改。const可以修饰变量、指针、引用等不同的对象&#xff0c;并且具体的作用取决于const的修饰位置。理解const的规则能够帮助我们…...

avcodec_alloc_context3,avcodec_open2,avcodec_free_context,avcodec_close

avcodec_alloc_context3 是创建编解码器上下文&#xff0c;需要使用 avcodec_free_context释放 需要使用avcodec_free_context 释放 /** * Allocate an AVCodecContext and set its fields to default values. The * resulting struct should be freed with avcodec_free_co…...

强化学习的几个主要方法(策略梯度、PPO、REINFORCE实现等)(下)

由于平台字数限制&#xff0c;上文&#xff1a;https://blog.csdn.net/ooblack/article/details/144198538 4. PPO算法 近端策略优化&#xff08;proximal policy optimization&#xff0c;PPO&#xff09;算法是OpenAI的默认强化学习算法&#xff0c;在RLHF中也用到了这个算…...

计算机网络:IP协议详细讲解

目录 前言 一、IP网段划分 二、IP报头 三、解决IP地址不足-->NAT技术 前言 在之前&#xff0c;我们学习了传输层中的TCP和UDP&#xff0c;重点是TCP协议&#xff0c;他帮我们解决具体到主机的哪个应用&#xff08;端口&#xff09;、传输的可靠&#xff08;序列号、校验和…...

2024信创数据库TOP30之华为Gauss DB

近日&#xff0c;由DBC联合CIW/CIS共同发布的“2024信创数据库TOP30”榜单正式揭晓&#xff0c;汇聚了国内顶尖的数据库企业及其产品&#xff0c;成为展示中国信创领域技术实力与发展潜力的重要平台。在这份榜单中&#xff0c;华为的GaussDB凭借其卓越的技术实力、广泛的行业应…...

在线家具商城基于 SpringBoot:设计模式与实现方法探究

第3章 系统分析 用户的需求以及与本系统相似的在市场上存在的其它系统可以作为系统分析中参考的资料&#xff0c;分析人员可以根据这些信息确定出本系统具备的功能&#xff0c;分析出本系统具备的性能等内容。 3.1可行性分析 尽管系统是根据用户的要求进行制作&#xff0c;但是…...

九、Spring Boot集成Spring Security之授权概述

文章目录 往期回顾&#xff1a;Spring Boot集成Spring Security专栏及各章节快捷入口前言一、授权概述二、用户权限三、用户授权流程三、Spring Security授权方式1、请求级别授权2、方法级别授权 往期回顾&#xff1a;Spring Boot集成Spring Security专栏及各章节快捷入口 Spr…...

python之Flask入门—路由参数

语法&#xff1a; /routerName/<string:parameter_name> 其中&#xff1a;routerName代表路由名称<>中的string是参数类型&#xff0c;parameter_name为参数名称 参数类型&#xff1a; &#xff08;1&#xff09; string 接收任何没有斜杠&#xff08;/&#x…...

txt地图格式处理

1、txt地图格式 [属性描述] 坐标系2000国家大地坐标系 几度分带3 投影类型高斯克吕格 计量单位米 带号38 精度0.001 转换参数,,,,,, [地块坐标] 5,475.888,1,测试地块1,面,J50G077061,公路用地,地下, J1,1,113.22222222222222,23.129111721551794 J2,1,113.2722314…...

《数据挖掘:概念、模型、方法与算法(第三版)》

嘿&#xff0c;数据挖掘的小伙伴们&#xff01;今天我要给你们介绍一本超级实用的书——《数据挖掘&#xff1a;概念、模型、方法与算法》第三版。这本书是数据挖掘领域的经典之作&#xff0c;由该领域的知名专家编写&#xff0c;系统性地介绍了在高维数据空间中分析和提取大量…...

GitLab CVE-2024-8114 漏洞解决方案

漏洞 ID 标题严重等级CVE ID通过 LFS 令牌提升权限高CVE-2024-8114 GitLab 升级指南GitLab 升级路径查看版本漏洞查询 漏洞解读 此漏洞允许攻击者使用受害者的个人访问令牌&#xff08;PAT&#xff09;进行权限提升。影响从 8.12 开始到 17.4.5 之前的所有版本、从 17.5 开…...

request和websocket

当然&#xff0c;可以为你详细介绍 FastAPI 中的 Request 对象。Request 对象在 FastAPI 中扮演着重要的角色&#xff0c;负责封装来自客户端的 HTTP 请求信息。了解 Request 对象的使用方法和属性&#xff0c;有助于你更高效地处理请求数据、访问请求上下文以及进行各种操作。…...

label-studio的使用教程(导入本地路径)

文章目录 1. 准备环境2. 脚本启动2.1 Windows2.2 Linux 3. 安装label-studio机器学习后端3.1 pip安装(推荐)3.2 GitHub仓库安装 4. 后端配置4.1 yolo环境4.2 引入后端模型4.3 修改脚本4.4 启动后端 5. 标注工程5.1 创建工程5.2 配置图片路径5.3 配置工程类型标签5.4 配置模型5.…...

【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器

一.自适应梯度算法Adagrad概述 Adagrad&#xff08;Adaptive Gradient Algorithm&#xff09;是一种自适应学习率的优化算法&#xff0c;由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率&#xff0c;适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...

Unity3D中Gfx.WaitForPresent优化方案

前言 在Unity中&#xff0c;Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染&#xff08;即CPU被阻塞&#xff09;&#xff0c;这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案&#xff1a; 对惹&#xff0c;这里有一个游戏开发交流小组&…...

React Native 开发环境搭建(全平台详解)

React Native 开发环境搭建&#xff08;全平台详解&#xff09; 在开始使用 React Native 开发移动应用之前&#xff0c;正确设置开发环境是至关重要的一步。本文将为你提供一份全面的指南&#xff0c;涵盖 macOS 和 Windows 平台的配置步骤&#xff0c;如何在 Android 和 iOS…...

Spring Boot 实现流式响应(兼容 2.7.x)

在实际开发中&#xff0c;我们可能会遇到一些流式数据处理的场景&#xff0c;比如接收来自上游接口的 Server-Sent Events&#xff08;SSE&#xff09; 或 流式 JSON 内容&#xff0c;并将其原样中转给前端页面或客户端。这种情况下&#xff0c;传统的 RestTemplate 缓存机制会…...

DockerHub与私有镜像仓库在容器化中的应用与管理

哈喽&#xff0c;大家好&#xff0c;我是左手python&#xff01; Docker Hub的应用与管理 Docker Hub的基本概念与使用方法 Docker Hub是Docker官方提供的一个公共镜像仓库&#xff0c;用户可以在其中找到各种操作系统、软件和应用的镜像。开发者可以通过Docker Hub轻松获取所…...

【SpringBoot】100、SpringBoot中使用自定义注解+AOP实现参数自动解密

在实际项目中,用户注册、登录、修改密码等操作,都涉及到参数传输安全问题。所以我们需要在前端对账户、密码等敏感信息加密传输,在后端接收到数据后能自动解密。 1、引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序

一、开发准备 ​​环境搭建​​&#xff1a; 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 ​​项目创建​​&#xff1a; File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...

是否存在路径(FIFOBB算法)

题目描述 一个具有 n 个顶点e条边的无向图&#xff0c;该图顶点的编号依次为0到n-1且不存在顶点与自身相连的边。请使用FIFOBB算法编写程序&#xff0c;确定是否存在从顶点 source到顶点 destination的路径。 输入 第一行两个整数&#xff0c;分别表示n 和 e 的值&#xff08;1…...

dify打造数据可视化图表

一、概述 在日常工作和学习中&#xff0c;我们经常需要和数据打交道。无论是分析报告、项目展示&#xff0c;还是简单的数据洞察&#xff0c;一个清晰直观的图表&#xff0c;往往能胜过千言万语。 一款能让数据可视化变得超级简单的 MCP Server&#xff0c;由蚂蚁集团 AntV 团队…...