MyBatis的CRUD

1. what

MyBatis是一款优秀的持久层框架,它支持自定义SQL存储过程以及高级映射。MyBatis免除几乎所有的JDBC代码以及设置参数和获取结果集的工作。MyBatis可以通过简单的XML注解来配置和映射实体类型、接口、Java POJO(Plain Old Java Objects,普通老式Java对象)为数据库中的记录。

持久层:就是和数据库交互的一层——dao层,用于操作数据表记录的

框架:就是一个半成品,我们只需要引入该框架,加入自己的代码就可以完成相应的业务功能

持久层框架:MyBatis hirenate jpa等

ORM框架:Object Relative Mapping(对象关系映射)。表——实体类;一条记录——实体类的对象

表的字段——java实体类的属性

2. why

思考:JDBC操作数据库时代码量很大。

比如:查询时:需要手动给占位符赋值,需要手动把查询的结果封装到实体类中,需要手动关闭资源。

使用MyBatis可以帮你完成上面的操作。

3.快速搭建

1. 创建一个maven的java工程

File——New——New Project——Maven

Name : mybatis01

GroupId : com.zmq

2.引入MyBatis和mysql的依赖

 <dependencies>
<!--mybatis的依赖-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.9</version>
        </dependency>
<!--mysql的依赖-->
        <dependency>
            <groupId>repMaven.mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>
<!--lombok的依赖-->
        <dependency>
            <groupId>repMaven.org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.28</version>
        </dependency>
<!--junit依赖-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

引入的依赖有顺序,否则会报红,mybatis依赖需要在最前面

3.创建实体类,为了映射表中的记录

4.mybatis的配置文件——配置数据源信息

不需要背

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <!--name是固定的 value根据需要配置为自己的内容-->
                <property name="driver" value="com.mysql.cj.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/zmq?serverTimezone=Asia/Shanghai" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment>
    </environments>
</configuration>
  1. 修改为自己的数据库名称——
  2. 修改为自己的数据库用户名
  3. 修改为自己的数据库密码

5.mybatis的映射文件——编写自己的sql语句

在resources下创建mapper目录,在该目录下创建对应的映射文件——UserMapper.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">
<!--namespace:命名空间 

-->
<mapper namespace="aaa">
     <!--select:用于编写查询的sql语句
            id:唯一标签 
            resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上
     -->
    <select id="getById" resultType="com.zmq.entity.User">
        select * from user where id=#{id}
    </select>
</mapper>

6.将映射文件放入配置文件中

未来我们读取的只有配置文件

<!--引入映射文件-->
<mappers>
	<mapper resource="mapper/UserMapper.xml"/>
</mappers>

7.测试mybatis是否正确

 @Test
    public void test01() throws Exception{
        //1. 读取mybatis的配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2. 获取SqlSessionFactory对象---创建sqlSession的对象
        SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3. 获取SqlSession对象---表示java与数据库的一次连接
        SqlSession sqlSession=sessionFactory.openSession();
        //4. 执行sql语句
        //String statement, 执行映射文件中的哪个标签
        // Object parameter 需要的参数值
        User user= sqlSession.selectOne("aaa.getById",1);
        System.out.println(user);
    }

4. mybaits完成CRUD

4 .1 根据id查询

1.UserMapper.xml配置文件中写根据id查询的sql语句

<select id="getById" resultType="com.zmq.entity.User">
        select * from user where id=#{id}
    </select>
  1. select:用于编写查询的sql语句
  2. id:唯一标签
  3. resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上
  4. #{名称},相当于占位符

2.UserTest类中完成根据id查询的测试

//查询
    @Test
    public void test01() throws Exception{
        //1.读取mybatis的配置文件按
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.获取SqlSessionFactory对象
        SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.
        SqlSession sqlSession = sessionFactory.openSession();
        //4.
        User user = sqlSession.selectOne("UserMapper.getById",9);
        System.out.println(user);
    }

前三个步骤是固定的

  1. 首先:读取mybatis的配置文件,即mybatis.xml文件

  2. 获取SqlSessionFactory对象,创建sqlSession的对象

new SqlSessionFactoryBuilder().build(resourceAsStream)

  1. 获取SqlSession对象,表示java与数据库的一次连接

sessionFactory.openSession()

  1. 执行sql语句,有两个参数:

String statement, 执行映射文件中的哪个标签

Object parameter 需要的参数值

  1. 执行sql语句时,调用selectOne方法

4.2 添加

1.UserMapper.xml配置文件中写添加用户的sql语句

<!--增加-->
    <insert id="add">
        insert into user values (null,#{u_name},#{password})
    </insert>
  1. insert:用于编写添加的sql语句
  2. #{名称},必须和实体类属性名一致
  3. 实体类中id为Integer类型,不然后续测试时会报错
  4. 不需要resultType

2.UserTest类中完成添加用户的测试

//添加
    @Test
    public void testAdd() throws Exception{
        //1.读取mybatis的配置文件按
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.获取SqlSessionFactory对象——创建swssionFactory对象
        SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.获取sqlSession对象——java与数据库的一次连接
        SqlSession sqlSession = sessionFactory.openSession();
        //4.创建一个user对象,传入添加用户的信息
        User user=new User(null,"汪芜","123456");
        //5.执行sql语句
        int row = sqlSession.insert("UserMapper.add", user);
        //将数据提交到数据库中
        sqlSession.commit();
        System.out.println(row);
    }

增删改与查询的不同点:

  1. 因为执行sql语句时,传入的是一个对象,而不能一次传递多个值,所以需要创建一个user对象,将要传递的值放入到user对象中,再在执行sql语句中传递符合要求的user对象

User user=new User(null,“汪芜”,“123456”);

int row = sqlSession.insert(“UserMapper.add”, user);

  1. 在执行完sql语句后,必须要提交到数据库中

sqlSession.commit();

  1. 执行时调用insert方法

4.3 修改

1.UserMapper.xml配置文件中写修改的sql语句

<!--修改-->
    <update id="update">
        update user set u_name=#{name},password=#{password} where id=#{id}
    </update>

  1. update:用于编写修改的sql语句
  2. #{名称}:必须和实体类属性名一致

2.UserTest类中完成修改的测试

//修改
    @Test
    public void testUpdate() throws Exception {
        //1.读取mybatis的配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.获取SqlSessionFactory对象---创建sqlSession的对象
        SqlSessionFactory sessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.获取SqlSession对象---表示java与数据库的一次连接
        SqlSession sqlSession = sessionFactory.openSession();
        //4.创建一个user对象
        User user=new User(12,"lay","1007");
        //5.执行sql语句
        //  String statement, 执行映射文件中的哪个标签
        //  Object parameter 需要的参数值
        int row = sqlSession.update("UserMapper.update", user);
        //6.提交
        sqlSession.commit();
        System.out.println(row);
    }

  1. 和增加一样,需要创建一个user对象用来传递数据
  2. 执行时,调用update方法
  3. 执行完毕后,需要提交到数据库

4.4 删除

1.UserMapper.xml配置文件中写删除的sql语句

<!--删除-->
    <delete id="del">
        delete from user where id=#{id}
    </delete>

2.UserTest类中完成删除的测试

//删除
    @Test
    public void testDel() throws Exception {
        //1.创建mybatis的配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.创建SqlSessionFactory对象——创建sqlSession对象
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.获取sqlSession对象——表示java与数据库的一次连接
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4.执行sql语句
        int row = sqlSession.delete("UserMapper.del", 30);
        sqlSession.commit();
        System.out.println(row);
    }

  1. 因为删除只需要传递一个id,所以不需要和增江、修改一样创建一个对象来传递值
  2. 同样,在执行完毕sql语句后,需要提交到数据库

5.企业开发模式

上面我们操作数据库表记录都是使用SqlSession类中的方法,而实际开发中我们习惯自己写方法,调用自己的方法传递相应的参数。但是这些方法没有方法体{},在接口中。而方法的实现交于mybatis框架完成

1.创建一个接口

public interface UserDao {

    //根据id查询用户信息
    public User queryById(int id);
}

2.映射文件

<?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">
<!--namespace:命名空间必须和接口名一致
-->
<mapper namespace="com.zmq.dao.UserDao">
    <!--select:用于编写查询的sql语句
           id:唯一标签,必须和Dao接口中的方法名一致
           resultType:结果类型 sql执行完毕后返回对应的java实体类的类型 把查询的结果自动封装到该实体类的属性上
    -->
    <select id="getById" resultType="com.zmq.entity.User">
        select * from user where id=#{id}
    </select>
</mapper>

3.测试

public class UserTest {

    //根据id查询
    @Test
    public void testGetById() throws IOException {
        //1.获取mybatis的配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.获取SqlSessionFactory对象——创建sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.获取sqlSession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4.获取dao接口的代理实现类
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        //5.调用自己类中的方法
        User user = userDao.getById(12);
        System.out.println(user.getU_name());
    }
}

4.补充@Before注解

@Before注解:是Junit中的一个注解,它用于标记一个方法,在每个测试方法执行之前都会被自动调用。 通过使用@Before注解,我们可以将一些通用的准备操作(如创建对象、初始化变量等)放置在一个方法中,以避免在每个测试方法中重复编写相同的准备代码。

@Before注解可以将测试中的一些固定步骤提取出来

UserDao userDao=null;
SqlSession sqlSession=null;
@Before
public void before() throws Exception{
   //1.获取mybatis的配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //2.获取SqlSessionFactory对象——创建sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        //3.获取sqlSession对象
        sqlSession = sqlSessionFactory.openSession();
        //4.获取dao接口的代理实现类
      userDao=sqlSession.getMapper(UserDao.class); 
}

6.企业模式完成CRUD

6.0 前期准备

1.引入依赖

创建好一个mybatis的java工程后,需要在pom.xml文件中引入相关依赖

<dependencies>
<!--mybatis的依赖-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.9</version>
        </dependency>
<!--mysql的依赖-->
        <dependency>
            <groupId>repMaven.mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>
<!--lombok的依赖-->
        <dependency>
            <groupId>repMaven.org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.28</version>
        </dependency>
<!--junit依赖-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    <!--打印日志-->
    <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    <dependency>
    	<groupId>com.github.pagehelper</groupId>
    	<artifactId>pagehelper</artifactId>
    	<version>5.3.2</version>
	</dependency>
</dependencies>

2.在resources下创建配置文件——mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <!--name是固定的 value根据需要配置为自己的内容-->
                <property name="driver" value="com.mysql.cj.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/zmq?serverTimezone=Asia/Shanghai" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment>
    </environments>
</configuration>

3.创建相应的实体类——entity——Student

package com.zmq.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @program: mybatis01work
 * @description: 学生表
 * @author: 赵梦倩
 * @create: 2024-05-20 16:42
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
   private Integer id;
    private String name;
    private String phone;
    private String email;
    private String profession;
    private Integer age;
}

4.创建相应的接口——dao——StudentDao

package com.zmq.dao;

import com.zmq.entity.Student;

import java.util.List;

/**
 * @program: mybatis01work
 * @description: 学生表的相关方法接口
 * @author: 赵梦倩
 * @create: 2024-05-20 16:44
 **/
public interface StudentDao {
    //1.根据id查询
    public Student getById(int id);
    //2.查询所有
    public List<Student> getAll();
    //添加
    public int add(Student student);
    //修改
    public int update(Student student);
    //删除
    public int delete(int id);

}

5.创建mybatis的映射文件——mapper——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">
<!--namespace:命名空间 

-->
<mapper namespace="com.zmq.dao.StudentDao">
    
</mapper>

6.在配置文件中引入映射文件

  <!--引入映射文件-->
 <mappers>
    <mapper resource="mapper/StudentMapper.xml"/>
 </mappers>

6.1 查询所有

1.映射文件【StudentMapper.xml】中写sql语句

 <select id="getAll" resultType="com.zmq.entity.Student">
        select * from t_student
    </select>

2.单元测试类中测试方法

 @Test
    public void testGetAll() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentDao studentDao=sqlSession.getMapper(StudentDao.class);
        List<Student> all = studentDao.getAll();
        for (Student s:all) {
            System.out.println(s.getName());
        }
    }

6.2 根据id查询

1.映射文件【StudentMapper.xml】中写sql语句

<select id="getById" resultType="com.zmq.entity.Student">
        select * from t_student where id=#{id}
    </select>

2.单元测试类中测试方法

@Test
    public void testGetById() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentDao studentDao=sqlSession.getMapper(StudentDao.class);
        Student byId = studentDao.getById(2);
        System.out.println(byId.getName());
    }

6.3 添加

1.映射文件【StudentMapper.xml】中写sql语句

<insert id="add" >
        insert into t_student values (null,#{name},#{phone},#{email},#{profession},#{age})
    </insert>

2.单元测试类中测试方法

@Test
    public void testAdd() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentDao studentDao=sqlSession.getMapper(StudentDao.class);
        Student student=new Student(null,"张数","1007","110qq.com","软件工程",16);
        int add = studentDao.add(student);
        System.out.println(add);
        sqlSession.commit();
    } 

6.4 修改

1.映射文件【StudentMapper.xml】中写sql语句

  <update id="update">
        update t_student set name=#{name},phone=#{phone},email=#{email},profession=#{profession},age=#{age} where id=#{id}
    </update>

2.单元测试类中测试方法

@Test
    public void testUpdate() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentDao studentDao=sqlSession.getMapper(StudentDao.class);
        Student student=new Student(25,"张数三","1007","110qq.com","软件工程",16);
        int update = studentDao.update(student);
        System.out.println(update);
        sqlSession.commit();
    }

6.5 删除

1.映射文件【StudentMapper.xml】中写sql语句

<delete id="delete">
        delete from t_student where id=#{id}
</delete>

2.单元测试类中测试方法

@Test
    public void testDel() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        StudentDao studentDao=sqlSession.getMapper(StudentDao.class);
        int delete = studentDao.delete(25);
        System.out.println(delete);
        sqlSession.commit();
    }

7. idea安装的相关插件

插件1:MyBatisX

可以用于纠错

插件2:Lombok

帮忙生成set,get,toString,构造方法——通过注解

  • 引入lombok依赖
  <!--lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
        </dependency>

  • 实体类中使用lombok注解
//set和get以toString方法生成
@Data
//无参构造方法
@NoArgsConstructor
//有参构造方法
@AllArgsConstructor

8.易错点

8.1 导包时

两个xml文件要打开记事本粘贴

否则会报错——创建实例错误

8.2 获取结果name为空

因为创建实体类时属性与数据库表属性不一致导致

解决:实体类属性与数据库表属性完全一致

8.3 Mapped Statements collection does not contain

两种可能:

①写错名称

②配置文件中没有引入映射文件

其他错误:

①密码账号错误

②写错sql语句——在数据库中执行下

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/975915.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot+Mybatis-Plus实现动态数据源

目录 一、前言二、代码实现1&#xff09;工程结构2&#xff09;相关依赖3&#xff09;数据源拦截切面4&#xff09;动态数据源切换5&#xff09;核心配置类6&#xff09;使用 三、原理分析1&#xff09;mapper接口注入流程2&#xff09;动态数据源切换执行流程 四、声明式事务导…

进程概念、PCB及进程查看

文章目录 一.进程的概念进程控制块&#xff08;PCB&#xff09; 二.进程查看通过指令查看进程通过proc目录查看进程的cwd和exe获取进程pid和ppid通过fork()创建子进程 一.进程的概念 进程是一个运行起来的程序&#xff0c;而程序是存放在磁盘的&#xff0c;cpu要想执行程序的指…

字节火山引擎 DeepSeek 接入本地使用

文章目录 1. 火山引擎 DeepSeek 初体验2. 本地接入 火山引擎 DeepSeek API3. 新建 API KEY4. 直接使用 1. 火山引擎 DeepSeek 初体验 火山引擎官网 : https://www.volcengine.com/product/ark 火山云默认给每个模型赠送 50 万 tokens 推理免费额度 进来就会看到模型广场&#…

基于javaweb的SpringBoot个人博客系统设计和实现(源码+文档+部署讲解)

技术范围&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app、大数据、物联网、机器学习等设计与开发。 主要内容&#xff1a;免费功能设计、开题报告、任务书、中期检查PPT、系统功能实现、代码编写、论文编写和辅导、论…

《操作系统 - 清华大学》8 -4:进程管理:进程控制结构

深度剖析进程控制块&#xff1a;操作系统进程管理的核心关键 在操作系统的复杂体系中&#xff0c;进程控制块&#xff08;PCB&#xff09;是实现高效进程管理的关键所在。接下来&#xff0c;将从多个维度深入剖析进程控制块&#xff0c;帮助更好地理解其在操作系统中的重要作用…

Jupyter里面的manim编程学习

1.Jupyterlab的使用 因为我之前一直都是使用的vscode进行manim编程的&#xff0c;但是今天看的这个教程使用的是Jupyter&#xff0c;我也很是好奇这个manim在Jupyter这样的交互式下面会生成怎么样的效果&#xff0c;所以今天尝试了jupyter&#xff0c;并且对于两个进行比较和说…

孜然单授权系统V2.0PHP授权系统

孜然单授权V1.0系统&#xff0c;延续了2022年开发的孜然多应用授权系统V2.0 变更&#xff1a;多应用变单系统&#xff0c;去除没用的垃圾代码&#xff0c;从0开发&#xff0c;去除了一些没用的功能 完善了开发文档&#xff0c;之前那套是我写着玩的屎山代码&#xff0c;V1.0将展…

输入菜单关键字,遍历匹配到 menuIds,展开 匹配节点 的所有父节点以及 匹配节点 本身,高亮 匹配节点

菜单检索&#xff0c;名称、地址、权限标志 等 关键字匹配、展开、高亮(全程借助 DeepSeek ) 便捷简洁的企业官网 的后台菜单管理&#xff0c;图示&#xff1a; 改造点&#xff1a; &#xff08;1&#xff09;修改 bootstrapTreeTable 的节点class命名方式为&#xff1a;treeg…

【落羽的落羽 数据结构篇】顺序结构的二叉树——堆

文章目录 一、堆1. 概念与分类2. 结构与性质3. 入堆4. 出堆 二、堆排序三、堆排序的应用——TOP-K问题 一、堆 1. 概念与分类 上一期我们提到&#xff0c;二叉树的实现既可以用顺序结构&#xff0c;也可以用链式结构。本篇我们来学习顺序结构的二叉树&#xff0c;起个新名字—…

数据结构系列一:初识集合框架+复杂度

前言 数据结构——是相互之间存在一种或多种特定关系的数据元素的集合。数据结构是计算机专业的基础课程&#xff0c;但也是一门不太容易学好的课&#xff0c;它当中有很多费脑子的东西&#xff0c;之后在学习时&#xff0c;你若碰到了困惑或不解的地方 都是很正常的反应&…

Python 入门教程(2)搭建环境 | 2.3、VSCode配置Python开发环境

文章目录 一、VSCode配置Python开发环境1、软件安装2、安装Python插件3、配置Python环境4、包管理5、调试程序 前言 Visual Studio Code&#xff08;简称VSCode&#xff09;以其强大的功能和灵活的扩展性&#xff0c;成为了许多开发者的首选。本文将详细介绍如何在VSCode中配置…

VSCode自定义快捷键和添加自定义快捷键按键到状态栏

VSCode自定义快捷键和添加自定义快捷键按键到状态栏 &#x1f4c4;在VSCode中想实现快捷键方式执行与某些指令操作进行绑定&#xff0c;可以通过配置组合式的键盘按键映射来实现&#xff0c;另外一种方式就是将执行某些特定的指令嵌入在面板菜单上&#xff0c;在想要执行的时候…

Linux系统安装MySQL5.7(其他版本类似)避坑指南

1.远程连接 在Linux系统安装好MySQL5.7数据库&#xff0c;不要以为就大功告成了后面还有大坑等着你踩了。宏哥这里介绍一下远程连接遇到的坑以及如何处理。由于征文要求安装环境教学除外宏哥这里就不介绍在Linux系统安装mysql数据库&#xff0c;有需要的可以自己百度一下。但是…

HybridCLR+Adressable+Springboot热更

本文章会手把手教大家如何搭建HybridCLRAdressableSpringboot热更。 创作不易&#xff0c;动动发财的小手点个赞。 安装华佗 首先我们按照官网的快速上手指南搭建一个简易的项目&#xff1a; 快速上手 | HybridCLR 注意在热更的代码里添加程序集。把用到的工具放到程序集里…

C语言(12)--------->for循环

在C语言中&#xff0c;有三大结构&#xff1a;顺序、选择、循环。这些结构可以用于处理生活中各种各样的复杂问题。选择结构通常是用if语句或者switch语句实现&#xff0c;可参考前面的博客&#xff1a; C语言&#xff08;7&#xff09;------------&#xff1e;if语句CSDN C…

react路由总结

目录 一、脚手架基础语法(16~17) 1.1、hello react 1.2、组件样式隔离(样式模块化) 1.3、react插件 二、React Router v5 2.1、react-router-dom相关API 2.1.1、内置组件 2.1.1.1、BrowserRouter 2.1.1.2、HashRouter 2.1.1.3、Route 2.1.1.4、Redirect 2.1.1.5、L…

JAVA最新版本详细安装教程(附安装包)

目录 文章自述 一、JAVA下载 二、JAVA安装 1.首先在D盘创建【java/jdk-23】文件夹 2.把下载的压缩包移动到【jdk-23】文件夹内&#xff0c;右键点击【解压到当前文件夹】 3.如图解压会有【jdk-23.0.1】文件 4.右键桌面此电脑&#xff0c;点击【属性】 5.下滑滚动条&…

拆解微软CEO纳德拉战略蓝图:AI、量子计算、游戏革命如何改写未来规则!

2025年2月19日 知名博主Dwarkesh Patel对话微软CEO萨蒂亚纳德拉 在最新访谈释放重磅信号&#xff1a;AI将掀起工业革命级增长&#xff0c;量子计算突破引爆材料科学革命&#xff0c;游戏引擎进化为世界模拟器。 整个视频梳理出几大核心观点&#xff0c;揭示科技巨头的未来十年…

记录此刻:历时两月,初步实现基于FPGA的NVMe SSD固态硬盘存储控制器设计!

背景 为满足实验室横向项目需求&#xff0c;在2024年12月中下旬导师提出基于FPGA的NVMe SSD控制器研发项目。项目核心目标为&#xff1a;通过PCIe 3.0 x4接口实现单盘3000MB/s的持续读取速率。 实现过程 调研 花了半个月的时间查阅了一些使用FPGA实现NVME SSD控制器的论文、…

Grok 3与GPT-4.5的“智能天花板”争夺战——谁才是大模型时代的算力之王?

2025年2月18日&#xff0c;马斯克旗下 xAI 高调发布新一代大模型Grok 3&#xff0c;号称“地球上最聪明AI”&#xff0c;在数学推理、代码生成等核心能力上碾压 GPT-4o、DeepSeek-V3 等对手。而就在同一天&#xff0c;OpenAI创始人 Sam Altman 暗示 GPT-4.5 即将登场&#xff0…