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

【Spring Boot】035-Spring Boot 整合 MyBatis Plus

【Spring Boot】035-Spring Boot 整合 MyBatis Plus

【Spring Boot】010-Spring Boot整合Mybatis

https://blog.csdn.net/qq_29689343/article/details/108621835

文章目录

  • 【Spring Boot】035-Spring Boot 整合 MyBatis Plus
  • 一、MyBatis Plus 概述
    • 1、简介
    • 2、特性
    • 3、结构图
    • 4、相关资料
  • 二、Spring Boot 整合 MyBatis Plus
    • 1、引入依赖
      • 核心依赖
      • 完整 pom.xml 文件
    • 2、数据源配置
    • 3、演示数据
      • 建表语句
      • 示例数据
    • 4、基础代码和配置
      • 实体类
      • Mapper 接口
      • StudentMapper.xml
      • 启动类上配置 mapper 扫描路径
      • 测试类
      • 运行结果
      • 代码结构截图
  • 三、MyBatis Plus 核心特性使用
    • 1、CRUD基础接口
      • insert 型接口
      • delete 型接口
      • update 型接口
      • select 型接口
    • 2、Wrapper 机制
      • 基本使用
      • lambda 式使用
      • 投影查询
      • 聚合查询
    • 3、主键策略与ID生成器
    • 4、逻辑删除
      • application.yaml 中配置
      • 在实体类的 deleted 属性上标记 @TableLogic 注解
      • 数据表中加上 deleted 字段
      • 删除测试
      • 逻辑删除结果
    • 5、乐观锁插件
      • 第一步:注册乐观锁插件
      • 第二步:实体类添加 `@Version` 注解
    • 6、分页插件
      • 第一步:添加分页插件
      • 第二步:使用分页模型

一、MyBatis Plus 概述

1、简介

MyBatis Plus 为简化开发而生!

MyBatis Plus(简称 MyBatis-Plus 或 MP)是 MyBatis 的增强工具包,它在 MyBatis 的基础上提供了很多便捷的功能,简化了开发过程。

只做增强,不做改变、效率至上,功能丰富。

2、特性

  • CRUD 操作的增强支持: MyBatis Plus 提供了更简单、更便捷的方式进行 CRUD 操作,减少了开发者的工作量。
  • 条件构造器: MyBatis Plus 引入了条件构造器,可以通过简单的链式调用来构建复杂的查询条件,避免了手写 SQL 语句的繁琐。
  • 代码生成器: MyBatis Plus 提供了代码生成器,可以根据数据库表自动生成对应的实体类、Mapper 接口以及 XML 文件,提高了开发效率。
  • 分页插件: MyBatis Plus 集成了分页插件,可以方便地进行分页查询,支持多种数据库的分页方式。
  • 性能优化: MyBatis Plus 对 MyBatis 进行了一些性能上的优化,提高了系统的运行效率。
  • 通用 Mapper: MyBatis Plus 提供了通用 Mapper 的功能,可以通过继承 BaseMapper 接口来实现通用的 CRUD 操作,减少了编码量。
  • 自动填充: MyBatis Plus 支持自动填充功能,可以在插入和更新操作时自动填充指定的字段,如创建时间、更新时间等。

3、结构图

img

4、相关资料

官网:https://baomidou.com/

github:https://github.com/baomidou/mybatis-plus

二、Spring Boot 整合 MyBatis Plus

1、引入依赖

核心依赖

<!-- MySQL -->
<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope>
</dependency><!-- MyBatis-Plus -->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.2</version>
</dependency>

完整 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.17</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.zibo</groupId><artifactId>study-mp</artifactId><version>0.0.1-SNAPSHOT</version><name>study-mp</name><description>study-mp</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- MySQL --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><!-- MyBatis-Plus --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.2</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><image><builder>paketobuildpacks/builder-jammy-base:latest</builder></image><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

2、数据源配置

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8username: rootpassword: 123456

3、演示数据

建表语句

CREATE TABLE `student` (`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名字',`age` int unsigned NOT NULL COMMENT '年龄',PRIMARY KEY (`id`),UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='用户';

示例数据

INSERT INTO `study`.`student`(`id`, `name`, `age`) VALUES (1, '訾博', 27);
INSERT INTO `study`.`student`(`id`, `name`, `age`) VALUES (2, 'zibo', 25);
INSERT INTO `study`.`student`(`id`, `name`, `age`) VALUES (3, 'zb', 23);

4、基础代码和配置

实体类

MyBatisPlus 拥有非常优秀的单表 CRUD 基础能力,而这个能力需要在实体类上做一些改动。通过标注 @TableName 注解,相当于告诉 MyBatisPlus 当前这个 Student 类要映射到 student 表(默认表名策略是驼峰转下划线);通过给 id 属性标注 @TableId 注解,并声明 ID 类型为 auto ,相当于适配 MySQL 中的自增主键。其他属性与数据库中映射均一致,就不再需要添加新注解了。

package com.zibo.studymp.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;@Data
@TableName("student")
public class Student {@TableId(type = IdType.AUTO)private Integer id;private String name;private Integer age;
}

Mapper 接口

MyBatisPlus 的单表 CRUD 能力来自一个内置的基础接口 BaseMapper ,通过继承 BaseMapper 并注明实体类的泛型类型,即可拥有单表的 CRUD 能力。

package com.zibo.studymp.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zibo.studymp.entity.Student;public interface StudentMapper extends BaseMapper<Student> {Student getByName(String name);}

StudentMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.zibo.studymp.mapper.StudentMapper"><select id="getByName" resultType="com.zibo.studymp.entity.Student">SELECT *FROM `student`WHERE `name` = #{name}</select></mapper>

启动类上配置 mapper 扫描路径

@MapperScan({“com.zibo.**.mapper”})

package com.zibo.studymp;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan({"com.zibo.**.mapper"})
public class StudyMpApplication {public static void main(String[] args) {SpringApplication.run(StudyMpApplication.class, args);}}

测试类

package com.zibo.studymp;import com.zibo.studymp.entity.Student;
import com.zibo.studymp.mapper.StudentMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class StudyMpApplicationTests {@Autowiredprivate StudentMapper studentMapper;@Testvoid contextLoads() {Student student = studentMapper.selectById(1);System.out.println(student);System.out.println("==================================");student = studentMapper.getByName("zibo");System.out.println(student);}}

运行结果

Student(id=1, name=訾博, age=27)
==================================
Student(id=2, name=zibo, age=25)

代码结构截图

image-20231113201325051

三、MyBatis Plus 核心特性使用

1、CRUD基础接口

MyBatisPlus 提供的重要基础能力,就是替我们开发者实现了基本的单表 CRUD 操作,我们在编写具体的业务模块时,单表的 CRUD 可以完全不需要编写了,仅需要继承 BaseMapper 接口,该 Mapper 接口就可以自动拥有单表 CRUD 的能力。

insert 型接口

// 插入一条记录
int insert(T entity);

delete 型接口

// 根据 entity 条件,删除记录
int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
// 删除(根据ID 批量删除)
int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// 根据 ID 删除
int deleteById(Serializable id);
// 根据 columnMap 条件,删除记录
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);

update 型接口

// 根据 whereWrapper 条件,更新记录
int update(@Param(Constants.ENTITY) T updateEntity, @Param(Constants.WRAPPER) Wrapper<T> whereWrapper);
// 根据 ID 修改
int updateById(@Param(Constants.ENTITY) T entity);

select 型接口

// 根据 ID 查询
T selectById(Serializable id);
// 根据 entity 条件,查询一条记录
T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);// 查询(根据ID 批量查询)
List<T> selectBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// 根据 entity 条件,查询全部记录
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 查询(根据 columnMap 条件)
List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
// 根据 Wrapper 条件,查询全部记录
List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根据 Wrapper 条件,查询全部记录。注意: 只返回第一个字段的值
List<Object> selectObjs(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);// 根据 entity 条件,查询全部记录(并翻页)
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根据 Wrapper 条件,查询全部记录(并翻页)
IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// 根据 Wrapper 条件,查询总记录数
Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

2、Wrapper 机制

Wrapper 是 MyBatisPlus 编程式查询、修改数据的重要特性,这种特性类似于 Hibernate 中的 Criteria 机制(也就是 QBC 查询)。MyBatis 提供的 Wrapper 机制拥有对单表查询的灵活条件构造、投影查询、聚合查询等能力。下面通过几个简单示例来了解 Wrapper 的使用。

基本使用

    @Testvoid test01() {// wrapper 基本使用QueryWrapper<Student> wrapper = new QueryWrapper<>();wrapper.eq("name", "zibo");Student student = studentMapper.selectOne(wrapper);System.out.println(student);}

lambda 式使用

为了更容易维护可能变化的实体模型类属性,MyBatisPlus 提供了 LambdaWrapper ,使用这种类型的 Wrapper 将属性的字符串变量改为 Lambda 表达式,以此实现代码的高可维护性。

    @Testvoid test02() {// lambda 式使用LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();wrapper.eq(Student::getName, "zibo");Student student = studentMapper.selectOne(wrapper);System.out.println(student);// lambda 式使用:链式调用String name = "訾博";student = studentMapper.selectOne(new LambdaQueryWrapper<Student>().eq(StringUtils.isNotBlank(name), Student::getName, name));System.out.println(student);}

投影查询

如果一个表的列特别多,而我们只需要查其中几列数据时,投影查询就显得非常重要了,通过指定需要查询的列,来达到节省数据库流量带宽的目的。

测试代码

    @Testvoid test03() {// 投影查询LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();wrapper.eq(Student::getName, "zibo");wrapper.select(Student::getName, Student::getAge);Student student = studentMapper.selectOne(wrapper);System.out.println(student);}

查询结果

Student(id=null, name=zibo, age=25)

聚合查询

对于单表查询来讲,聚合查询也是一个常见的查询场景。虽然 MyBatisPlus 没有对几种聚合函数提供 API 的定义,不过我们可以传入 SQL 片段来曲线实现聚合查询。

测试代码

    @Testvoid test04() {// 聚合查询QueryWrapper<Student> wrapper = new QueryWrapper<>();wrapper.select("max(age) as age");Student student = studentMapper.selectOne(wrapper);System.out.println(student);}

执行结果

Student(id=null, name=null, age=27)

3、主键策略与ID生成器

MyBatisPlus 考虑到我们在项目开发中可能会用到的几种主键类型,它给予了一些基础实现和配置:

  • AUTO :数据库主键自增
  • ASSIGN_ID :雪花算法 ID
  • ASSIGN_UUID :不带短横线的 uuid
  • INPUT :程序手动设置的 id (或配合序列填充,Oracle 、SQLServer 等使用)
  • NONE :逻辑主键,数据库表中没有定义主键

默认情况下,MyBatisPlus 使用的主键策略是使用了雪花算法的 ASSIGN_ID 策略。

4、逻辑删除

下面简单了解 MyBatisPlus 中的两个简单实用的特性。

逻辑删除是代替 delete 物理删除的一种更适合项目开发的数据删除机制,它通过设置一个特殊的标志位,将需要删除的数据设置为“不可见”,并在每次查询数据时只查询标志位数据值为“可见”的数据,这样的设计即是逻辑删除。MyBatisPlus 使用逻辑删除非常简单,只需要两步即可。

application.yaml 中配置

mybatis-plus:global-config:db-config:logic-delete-field: deletedlogic-delete-value: 1logic-not-delete-value: 0

在实体类的 deleted 属性上标记 @TableLogic 注解

package com.zibo.studymp.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;@Data
@TableName("student")
public class Student {@TableId(type = IdType.AUTO)private Integer id;private String name;private Integer age;@TableLogicprivate Integer deleted;
}

数据表中加上 deleted 字段

image-20231113205456134

删除测试

    @Testvoid deleteTest() {// 删除int result = studentMapper.deleteById(1);System.out.println(result);}

逻辑删除结果

image-20231113205824253

5、乐观锁插件

乐观锁是高并发下控制的手段,它假设多用户并发的事务在处理时不会彼此互相影响,各事务能够在不产生锁的情况下处理各自影响的那部分数据。换句话说,乐观锁希望一条即将被更新的数据,没有被其他人操作过。

乐观锁的实现方式如下:

  • 给数据添加 version 属性
  • 当查询数据时,把 version 数据一并带出
  • 更新数据时,将查询的 version 数据值一并传入
  • 执行 update / delete 语句时,额外在 where 条件中添加 version = ? 语句
  • 如果 version 数据与数据库中的不一致,则更新 / 删除失败

MyBatisPlus 中实现的乐观锁机制是通过插件实现。使用乐观锁需要以下两个步骤:

第一步:注册乐观锁插件

@Configuration(proxyBeanMethods = false)
public class MyBatisPlusConfiguration {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();// 添加乐观锁插件interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());return interceptor;}
}

第二步:实体类添加 @Version 注解

package com.zibo.studymp.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import lombok.Data;@Data
@TableName("student")
public class Student {@TableId(type = IdType.AUTO)private Integer id;private String name;private Integer age;@TableLogicprivate Integer deleted;@Versionprivate Integer version;
}

以此法编写完毕后,在 student 表的单表数据操作时,乐观锁就会介入处理。

需要注意的是,MyBatisPlus 支持的乐观锁,可以对以下的数据类型予以支持:

  • int long
  • Integer Long
  • Date Timestamp LocalDateTime

6、分页插件

分页查询是项目开发中非常常见的业务场景,对于 MyBatis 的分页插件而言可能之前比较常见的是 PageHelper ,MyBatisPlus 已经考虑到了分页查询的场景,它提供了一个专门用于分页的插件,通过简单的配置就可以使用分页的特性。

第一步:添加分页插件

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();// 添加乐观锁插件interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());// 添加分页插件interceptor.addInnerInterceptor(new PaginationInnerInterceptor(new MySqlDialect()));return interceptor;
}

第二步:使用分页模型

在进行分页查询时,需要传入 IPage 对象,并返回 IPage 模型或 List 集合。以下是几个示例。

    /*** 使用IPage作为入参和返回值* @param query* @return*/IPage<Student> page(IPage<Student> query);/*** 使用集合作为返回值* @param query* @return*/List<Student> pageList(IPage<Student> query);/*** 使用IPage和其他参数共同作为入参* @param page* @param params* @return*/IPage<Student> pageParams(@Param("page") IPage<Student> page, @Param("params") Map<String, Object> params);

相关文章:

【Spring Boot】035-Spring Boot 整合 MyBatis Plus

【Spring Boot】035-Spring Boot 整合 MyBatis Plus 【Spring Boot】010-Spring Boot整合Mybatis https://blog.csdn.net/qq_29689343/article/details/108621835 文章目录 【Spring Boot】035-Spring Boot 整合 MyBatis Plus一、MyBatis Plus 概述1、简介2、特性3、结构图4、相…...

Hafnium之强制性的接口

安全之安全(security)博客目录导读 目录 一、FFA_VERSION 二、FFA_FEATURES 三、FFA_RXTX_MAP/FFA_RXTX_UNMAP 四、FFA_PARTITION_INFO_GET 五、FFA_PARTITION_INFO_GET_REGS...

计算机视觉:使用opencv实现银行卡号识别

1 概述 1.1 opencv介绍 OpenCV是Open Source Computer Vision Library&#xff08;开源计算机视觉库&#xff09;的简称&#xff0c;由Intel公司在1999年提出建立&#xff0c;现在由Willow Garage提供运行支持&#xff0c;它是一个高度开源发行的计算机视觉库&#xff0c;可以…...

【Proteus仿真】【Arduino单片机】简易计算器设计

文章目录 一、功能简介二、软件设计三、实验现象联系作者 一、功能简介 本项目使用Proteus8仿真Arduino单片机控制器&#xff0c;使用PCF8574、LCD1602液晶、4*4矩阵键盘等。 主要功能&#xff1a; 系统运行后&#xff0c;操作矩阵按键可实现简单四则运算。 二、软件设计 /* …...

pychon/PIL/opencv/json学习过程中遇到的问题

1. 使用PIL.Image读取图片 注意&#xff1a;pytorch中对图像预处理是transforms的输入必须是PIL格式的文件&#xff0c;使用cv2读取的图片就按照第二条的代码处理&#xff08;3通道合并、归一化处理&#xff09; from PIL import Image img Image.open("test1.jpg"…...

YOLO目标检测——番茄数据集下载分享【含对应voc、coco和yolo三种格式标签】

实际项目应用&#xff1a;番茄检测数据集说明&#xff1a;番茄目标检测数据集&#xff0c;真实场景的高质量图片数据&#xff0c;数据场景丰富标签说明&#xff1a;使用lableimg标注软件标注&#xff0c;标注框质量高&#xff0c;含voc(xml)、coco(json)和yolo(txt)三种格式标签…...

(JAVA)线程

线程的创建 方式一&#xff1a;Thread public class dome {public static void main(String[] args) {MyThread myThread new MyThread();myThread.start();for(int i1;i<5;i){System.out.println("主线程"i);}} }public class MyThread extends Thread{Overri…...

【深度学习环境】windows安装 NVIDIA Docker

摘要 不要安装 Docker Desktop&#xff01;我们将在 Ubuntu 中自行安装 Docker。 请安装 Windows 10 Insider Build 或 Windows 11 &#xff08;Beta也行&#xff09;。&#xff08;稳定发行版无法在 WSL 2 中使用 GPU&#xff09; 请安装 WSL 2 w/Ubuntu 20.04 或同等版本。…...

【微信小程序】自定义组件(三)

自定义组件 插槽1、什么是插槽2、单个插槽3、定义多个插槽 父子组件之间的通信1、父子组件之间的通信的3种方式2、事件绑定3、behaviors 插槽 1、什么是插槽 在自定义组件的wxml结构中&#xff0c;可以提供一个<solot> 节点&#xff08;插槽&#xff09;&#xff0c;用…...

Python语言:经典案例分析讲解2

例题1&#xff1a;文件的操作 例题2&#xff1a;调用函数求偶数之和 例题3&#xff1a;调用函数并使用递归的方法求斐波那契数前N项之和 题1: 以只写的模式打开文件test.txt&#xff0c;写入"Python"&#xff0c;关闭文件。 代码如下&#xff1a; f open("E:/…...

dbeaver连接别人的数据库没有表

1.概念 非缺省的数据库&#xff1a; 通常是指在一个数据库管理系统&#xff08;DBMS&#xff09;中&#xff0c;除了系统默认创建的数据库之外的其他用户创建或自定义的数据库。许多数据库系统在安装后会创建一个默认数据库&#xff0c;例如MySQL中的mysql数据库&#xff0c;…...

EXIT(1)

EXTI介绍 EXTI是片上外设 NVIC是cpu内的外设 回忆起之前的GPIO和AFIO 我们是如何检测按键按下的 我们是一直用while循环读取IDR寄存器的对应位置的值 一直检测判断按键是否被按下 那么是否有第二种方式检测按键是否被按下了呢&#xff1f; 通过EXTI 当EXTI检测到按键的电平发生…...

Qt信号量用于对共享资源进行同步

定义信号量与缓冲区&#xff1a; const int BufferSize 8; int buffer1[BufferSize]; int buffer2[BufferSize]; int curBuf1; //当前正在写入的Bufferint bufNo0; //采集的缓冲区序号quint8 counter0;//数据生成器QSemaphore emptyBufs(2);//信号量&#xff1a;空的缓冲区…...

在报错中学python something

这里写目录标题 动手学深度学习pandas完整代码数据处理TypeError: can only concatenate str (not "int") to str&#xff08;fillna填补缺失值&#xff09; 创建文件夹学习这个数据分组get_dummies实现one hot encode 动手学深度学习pandas完整代码 import osimpor…...

如何调用 DBMS_DISKGROUP 对 ASM 文件进行随机读取

目录 一、概述 二、实现思路与注意点 三、Java Demo 1、直接调用 2、读写异步 一、概述 对于 Oracle Rac 环境下,数据文件大多默认存放在 ASM 共享存储上,当我们需要读取 ASM 上存储的数据文件时可以使用 Oracle 提供的一些方法,比如 ASMCMD CP。但是,对于一些备份场景…...

UART学习

uart.c #include "stm32mp1xx_gpio.h" #include "stm32mp1xx_uart.h" // UART4_TX : PG11 AF6 // UART4_RX : PB2 AF8 void __uart_init() {// GPIOB2 设置为复用功能GPIOB->MODER & (~(0x3 << 4));GPIOB->MODER | (0x2 << 4);G…...

洗地机哪个牌子最好用?洗地机品牌排行榜

近年来&#xff0c;洗地机相当热门&#xff0c;洗地机结合了扫地拖地吸地为一体的多功能清洁工具&#xff0c;让我们告别了传统方式打扫卫生&#xff0c;让我们清洁不再费劲&#xff0c;可是市面上的洗地机五花八门&#xff0c;怎么挑选到一个洗地机也是一个问题&#xff0c;下…...

国际阿里云:Windows实例中数据恢复教程!!!

在处理磁盘相关问题时&#xff0c;您可能会碰到操作系统中数据盘分区丢失的情况。本文介绍了Windows系统下常见的数据盘分区丢失的问题以及对应的处理方法&#xff0c;同时提供了使用云盘的常见误区以及最佳实践&#xff0c;避免可能的数据丢失风险。 前提条件 已注册阿里云账…...

浅谈二叉树

✏️✏️✏️今天给大家分享一下二叉树的基本概念以及性质、二叉树的自定义实现&#xff0c;二叉树的遍历等。 清风的CSDN博客 &#x1f61b;&#x1f61b;&#x1f61b;希望我的文章能对你有所帮助&#xff0c;有不足的地方还请各位看官多多指教&#xff0c;大家一起学习交流&…...

(二) 用QWebSocket 实现服务端和客户端(详细代码直接使用)

目录 前言 一、服务器的代码&#xff1a; 1、服务器的思路 2、具体服务器的代码示例 二、客户端的代码&#xff1a; 1、客户端的思路&#xff08;和服务器类似&#xff09; 2、具体客户端的代码示例 前言 要是想了解QWebSocket的详细知识&#xff0c;还得移步到上一篇文…...

基于算法竞赛的c++编程(28)结构体的进阶应用

结构体的嵌套与复杂数据组织 在C中&#xff0c;结构体可以嵌套使用&#xff0c;形成更复杂的数据结构。例如&#xff0c;可以通过嵌套结构体描述多层级数据关系&#xff1a; struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...

浅谈 React Hooks

React Hooks 是 React 16.8 引入的一组 API&#xff0c;用于在函数组件中使用 state 和其他 React 特性&#xff08;例如生命周期方法、context 等&#xff09;。Hooks 通过简洁的函数接口&#xff0c;解决了状态与 UI 的高度解耦&#xff0c;通过函数式编程范式实现更灵活 Rea…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

Android Wi-Fi 连接失败日志分析

1. Android wifi 关键日志总结 (1) Wi-Fi 断开 (CTRL-EVENT-DISCONNECTED reason3) 日志相关部分&#xff1a; 06-05 10:48:40.987 943 943 I wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED bssid44:9b:c1:57:a8:90 reason3 locally_generated1解析&#xff1a; CTR…...

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...

Zustand 状态管理库:极简而强大的解决方案

Zustand 是一个轻量级、快速和可扩展的状态管理库&#xff0c;特别适合 React 应用。它以简洁的 API 和高效的性能解决了 Redux 等状态管理方案中的繁琐问题。 核心优势对比 基本使用指南 1. 创建 Store // store.js import create from zustandconst useStore create((set)…...

Day131 | 灵神 | 回溯算法 | 子集型 子集

Day131 | 灵神 | 回溯算法 | 子集型 子集 78.子集 78. 子集 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a; 笔者写过很多次这道题了&#xff0c;不想写题解了&#xff0c;大家看灵神讲解吧 回溯算法套路①子集型回溯【基础算法精讲 14】_哔哩哔哩_bilibili 完…...

FastAPI 教程:从入门到实践

FastAPI 是一个现代、快速&#xff08;高性能&#xff09;的 Web 框架&#xff0c;用于构建 API&#xff0c;支持 Python 3.6。它基于标准 Python 类型提示&#xff0c;易于学习且功能强大。以下是一个完整的 FastAPI 入门教程&#xff0c;涵盖从环境搭建到创建并运行一个简单的…...

JVM垃圾回收机制全解析

Java虚拟机&#xff08;JVM&#xff09;中的垃圾收集器&#xff08;Garbage Collector&#xff0c;简称GC&#xff09;是用于自动管理内存的机制。它负责识别和清除不再被程序使用的对象&#xff0c;从而释放内存空间&#xff0c;避免内存泄漏和内存溢出等问题。垃圾收集器在Ja…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...