Mybatis 多对一和一对多查询
文章目录
- Mybatis 多对一 and 一对多查询详解
- 数据库
- 需求
- Mybatis代码
- 注意
Mybatis 多对一 and 一对多查询详解
数据库
员工表 t_emp
部门表 t_dept
CREATE TABLE `t_emp` (`emp_id` int NOT NULL AUTO_INCREMENT,`emp_name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`age` int DEFAULT NULL,`gender` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`dept_id` int DEFAULT NULL,PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;CREATE TABLE `t_dept` (`dept_id` int NOT NULL AUTO_INCREMENT,`dept_name` varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,PRIMARY KEY (`dept_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;INSERT INTO `t_emp` (`emp_id`, `emp_name`, `age`, `gender`, `dept_id`) VALUES (1, '张三', 20, '男', 1), (2, '李四', 22, '男', 2), (3, '王五', 23, '男', 3), (4, '赵六', 24, '男', 1);INSERT INTO `t_dept` (`dept_id`, `dept_name`) VALUES (1, 'A'), (2, 'B'), (3, 'C');
需求
多对一:员工表对应部门表
查询指定id的员工以及其对应的部门
一对多:部门表对应员工表
查询指定的部门以及其包含的员工
Mybatis代码
DeptMapper接口文件
package com.atguigu.mybatis.mapper;import com.ruanjian.pojo.Dept;
import com.ruanjian.pojo.Emp;
import org.apache.ibatis.annotations.Param;import java.util.List;public interface DeptMapper {// 一对多查询// 查询部门表中的员工信息// 需要在部门类中添加员工的集合 private List<Emp> emps;Dept getDeptAndEmpById(@Param("deptId") Integer deptId);// 分步查询// 1.先查出指定id的部门信息,部门信息中有对应员工的dept_idDept getDeptAndEmpByStepOne(@Param("deptId") int deptId);// 2.再根据dept_id查出相对应的员工信息List<Emp> getDeptAndEmpByStepTwo(@Param("deptId") int deptId);}
EmpMapper接口文件
package com.atguigu.mybatis.mapper;
import com.ruanjian.pojo.Dept;
import com.ruanjian.pojo.Emp;
import org.apache.ibatis.annotations.Param;public interface EmpMapper {// 多对一查询// 查询指定id员工以及该员工所对应的部门信息Emp getEmpAndDeptById(@Param("empId") Integer empId);Emp getEmpAndDeptById_association(@Param("empId") Integer empId);// 分步查询// 先从员工表中查询出指定id的员工的数据,该数据中有对应部门id// 再根据部门id从部门表中查询出对应的部门信息// 分步查询第一步Emp getEmpAndDeptByIdOne(@Param("empId") Integer empId);// 分步查询第二步Dept getEmpAndDeptByIdTwo(@Param("deptId") Integer deptId);
}
Dept类文件 部门实体类
package com.ruanjian.pojo;/*
员工对部门 是多对一,多对一是在多的那个类(员工类)中添加一个部门对象
部门对员工 是一对多,一对多是在一的那个类中(部门类)中添加一个员工集合对一 对的就是一个对象
对多 对的就是一个集合*/import java.util.List;// 部门实体类
public class Dept {private Integer deptId;private String deptName;private List<Emp> emps; // 添加的一个员工的集合public Dept() {}public Dept(Integer deptId, String deptName) {this.deptId = deptId;this.deptName = deptName;}public Integer getDeptId() {return deptId;}public void setDeptId(Integer deptId) {this.deptId = deptId;}public String getDeptName() {return deptName;}public void setDeptName(String deptName) {this.deptName = deptName;}public List<Emp> getEmps() {return emps;}public void setEmps(List<Emp> emps) {this.emps = emps;}@Overridepublic String toString() {return "Dept{" +"deptId=" + deptId +", deptName='" + deptName + '\'' +", emps=" + emps +'}';}
}
Emp类文件
员工实体类
package com.ruanjian.pojo;/*
员工对部门 是多对一,多对一是在多的那个类(员工类)中添加一个部门对象
部门对员工 是一对多,一对多是在一的那个类中(部门类)中添加一个员工集合对一 对的就是一个对象
对多 对的就是一个集合*/// 员工实体类// 对一就是对应的一个对象
// 对多就是对应的一个集合
public class Emp {private Integer empId;private String empName;private Integer age;private String gender;private Dept dept; // 加上一个部门的对象public Emp() {}public Emp(Integer empId, String empName, Integer age, String gender) {this.empId = empId;this.empName = empName;this.age = age;this.gender = gender;}public Integer getEmpId() {return empId;}public void setEmpId(Integer empId) {this.empId = empId;}public String getEmpName() {return empName;}public void setEmpName(String empName) {this.empName = empName;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public String getGender() {return gender;}public void setGender(String gender) {this.gender = gender;}public Dept getDept() {return dept;}public void setDept(Dept dept) {this.dept = dept;}@Overridepublic String toString() {return "Emp{" +"empId=" + empId +", empName='" + empName + '\'' +", age=" + age +", gender='" + gender + '\'' +", dept=" + dept +'}';}
}
DeptMapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.mybatis.mapper.DeptMapper"><!-- 处理一对多的映射关系1. collection2. 分步查询
-->
<!--*************************** 一对多 collection ****************************************--><resultMap id="deptAndEmpById_resultMap" type="dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result><!-- collection : 处理一对多的映射关系(处理集合类型的属性)--><!-- ofType表示的是集合中的类型--><collection property="emps" ofType="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result></collection></resultMap><!-- Dept getDeptAndEmpById(@Param("deptId") Integer deptId);--><select id="getDeptAndEmpById" resultMap="deptAndEmpById_resultMap">select *from t_deptleft join t_emp on t_dept.dept_id = t_emp.dept_idwhere t_dept.dept_id=#{deptId}</select><!--*************************** 一对多 collection ****************************************--><!--*************************** 一对多 分步查询 ****************************************--><resultMap id="deptAndEmpResultMapByStep" type="Dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result><collection property="emps"select="com.atguigu.mybatis.mapper.DeptMapper.getDeptAndEmpByStepTwo"column="dept_id"></collection></resultMap><!-- Dept getDeptAndEmpByStepOne(@Param("deptId") int deptId);// 先查出指定id的部门信息,部门信息中有对应员工的dept_id --><select id="getDeptAndEmpByStepOne" resultMap="deptAndEmpResultMapByStep">select * from t_dept where dept_id = #{deptId}</select><!-- List<Emp> getDeptAndEmpByStepTwo(@Param("deptId") int deptId);// 再根据dept_id查出相对应的员工信息--><select id="getDeptAndEmpByStepTwo" resultType="Emp">select * from t_emp where dept_id = #{deptId}</select></mapper>
EmpMapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.mybatis.mapper.EmpMapper"><!--处理多对一的映射关系有三种方法:第一种:级联方式处理第二种:association 处理多对一的映射关系(处理的是实体类类型的属性)第三种:分布查询--><!-- ************ 第一种:级联方式处理 *************** --><resultMap id="EmpAndDeptById_resultMap" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><result column="dept_id" property="dept.deptId"></result><result column="dept_name" property="dept.deptName"></result></resultMap><!--Emp getEmpAndDeptById(@Param("empId") Integer empId);--><select id="getEmpAndDeptById" resultMap="EmpAndDeptById_resultMap">select *from t_empleft join t_dept on t_emp.dept_id = t_dept.dept_idwhere t_emp.emp_id=#{empId}</select><!-- *********************************************--><!-- *************** 第二种 association ******************************--><!-- 第二种 association--><resultMap id="getEmpAndDeptById_association_resultMap" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><!--association: 处理多对一的映射关系(处理实体类类型的属性)property: 设置需要处理映射关系的属性的属性名javaType: 设置要处理的属性的类型, 就是把<association>标签下设置映射关系的字段,封装给某个类--><association property="dept" javaType="Dept"><id column="dept_id" property="deptId"></id><result column="dept_name" property="deptName"></result></association></resultMap><!-- Emp getEmpAndDeptById_association(@Param("empId") Integer empId);--><select id="getEmpAndDeptById_association" resultMap="getEmpAndDeptById_association_resultMap">select *from t_empleft join t_dept on t_emp.dept_id = t_dept.dept_idwhere t_emp.emp_id=#{empId}</select><!-- *********************************************--><!-- ****************** 第三种:分布查询 ***************************--><resultMap id="getEmpAndDeptByIdOne_resultMap" type="Emp"><id column="emp_id" property="empId"></id><result column="emp_name" property="empName"></result><result column="age" property="age"></result><result column="gender" property="gender"></result><!--property: 设置需要处理映射关系的属性的属性名select: 填写分步查询的sql的唯一标识,就是设置下一步要执行的sql语句column: 将上一个sql查询出的某个字段作为分步查询的下一个sql语句sql条件,相当于函数的参数,传给下一个sql语句fetchType: 在开启了延时加载的环境中,通过该属性设置当前的分步查询是否使用延迟加载有两个值:eager(立即加载) lazy(延迟加载)--><association property="dept"fetchType="eager"select="com.atguigu.mybatis.mapper.EmpMapper.getEmpAndDeptByIdTwo"column="dept_id"></association></resultMap><!-- Emp getEmpAndDeptByIdOne(@Param("empId") Integer empId);--><select id="getEmpAndDeptByIdOne" resultMap="getEmpAndDeptByIdOne_resultMap">select * from t_emp where emp_id = #{empId}</select><!-- Dept getEmpAndDeptByIdTwo(@Param("deptId") Integer deptId);--><select id="getEmpAndDeptByIdTwo" resultType="Dept">select * from t_dept where dept_id = #{deptId}</select><!-- *********************************************--></mapper>
ResultMapTest
import com.atguigu.mybatis.mapper.DeptMapper;
import com.atguigu.mybatis.mapper.EmpMapper;
import com.ruanjian.pojo.Dept;
import com.ruanjian.pojo.Emp;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;import java.io.IOException;public class ResultMapTest {private SqlSession session;/*处理多对一的映射关系有三种方法:第一种:级联方式处理第二种:association 处理多对一的映射关系(处理的是实体类类型的属性)第三种:分步查询*/// *********************** 多对一 ****************************************@Test// 第三种:分步查询public void textGetEmpAndDeptByIdOne() {EmpMapper mapper = session.getMapper(EmpMapper.class);Emp emp = mapper.getEmpAndDeptByIdOne(1);System.out.println(emp);}@Test// 第二种:associationpublic void textGetEmpAndDeptById_association() {EmpMapper mapper = session.getMapper(EmpMapper.class);Emp emp = mapper.getEmpAndDeptById_association(2);System.out.println(emp);}@Test// 第一种:级联方式处理public void textGetEmpAndDeptById() {EmpMapper mapper = session.getMapper(EmpMapper.class);Emp emp = mapper.getEmpAndDeptById(2);System.out.println(emp);}// *********************** 一对多 ****************************************@Test// 分步查询public void textGetDeptAndEmpByStep() {DeptMapper mapper = session.getMapper(DeptMapper.class);Dept dept = mapper.getDeptAndEmpByStepOne(2);System.out.println(dept);}@Test// 一对多查询public void textGetDeptAndEmpById() {DeptMapper mapper = session.getMapper(DeptMapper.class);Dept dept = mapper.getDeptAndEmpById(1);System.out.println(dept);}// ***************************************************************// junit会在每一个@Test方法前执行@Before方法@Beforepublic void init() throws IOException {session = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml")).openSession();}// junit会在每一个@Test方法后执行@After方法@Afterpublic void clear() {session.commit();session.close();}
}
db.properties
mysql.driver=com.mysql.cj.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
mysql.username=root
mysql.password=123456
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"><appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"><param name="Encoding" value="UTF-8"/><layout class="org.apache.log4j.PatternLayout"><param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS} %m (%F:%L) \n"/></layout></appender><logger name="java.sql"><level value="debug"/></logger><logger name="org.apache.ibatis"><level value="info"/></logger><root><level value="debug"/><appender-ref ref="STDOUT"/></root>
</log4j:configuration>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!--环境配置--><!--引入外部db.properties--><properties resource="db.properties"/><settings><!-- <setting name="cacheEnabled" value="true" />--><!-- 开启延时加载--><setting name="lazyLoadingEnabled" value="true"/><!-- 开启时即为true时任何方法的调用都会加载相关类的全部属性false时是按需加载,true是全部加载--><setting name="aggressiveLazyLoading" value="false"/><setting name="mapUnderscoreToCamelCase" value="true"/></settings><typeAliases><package name="com.ruanjian.pojo"/></typeAliases><!--配置mybatis的连接环境(可以配置多个环境)--><environments default="development"><!--开发环境--><environment id="development"><!--使用JDBC事务管理--><transactionManager type="JDBC"/><!--数据库连接相关配置,db.properties文件中的内容--><!--使用连接池技术--><dataSource type="POOLED"><!--数据库驱动--><property name="driver" value="${mysql.driver}"/><!--连接字符串--><property name="url" value="${mysql.url}"/><!--数据库用户名--><property name="username" value="${mysql.username}"/><!--数据库密码--><property name="password" value="${mysql.password}"/></dataSource></environment></environments><!--mapping文件路径配置--><mappers><!-- <mapper resource="mapper/DeptMapper.xml"/>--><package name="com.atguigu.mybatis.mapper"/></mappers>
</configuration>
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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.itheima</groupId><artifactId>MyBaits_2</artifactId><version>1.0-SNAPSHOT</version><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build><properties><maven.compiler.sourece>11</maven.compiler.sourece><maven.compiler.target>11</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.11</version><scope>runtime</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>text</scope></dependency><!-- log4j日志 --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies>
</project>
注意
新建包时用点
例如:com.atguigu.mybatis.mapper
resources目录下建立多层目录的时候时是用分割线
例如:com/atguigu/mybatis/mapper
mybatis-config.xml文件中
<package name="com.atguigu.mybatis.mapper"/>
<package>的使用条件:
接口文件要和xml文件同名,并且在同一个目录下
使用注解写的接口,只能有class的方式注册,例:
<mapper class="com.atguigu.mybatis.mapper.DeptMapper"></mapper>
相关文章:

Mybatis 多对一和一对多查询
文章目录 Mybatis 多对一 and 一对多查询详解数据库需求Mybatis代码注意 Mybatis 多对一 and 一对多查询详解 数据库 员工表 t_emp 部门表 t_dept CREATE TABLE t_emp (emp_id int NOT NULL AUTO_INCREMENT,emp_name varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci…...

MySQL的数据库操作、数据类型、表操作
目录 一、数据库操作 (1)、显示数据库 (2)、创建数据库 (3)、删除数据库 (4)、使用数据库 二、常用数据类型 (1)、数值类型 (2࿰…...

音视频技术开发周刊 | 317
每周一期,纵览音视频技术领域的干货。 新闻投稿:contributelivevideostack.com。 MIT惊人再证大语言模型是世界模型!LLM能分清真理和谎言,还能被人类洗脑 MIT等学者的「世界模型」第二弹来了!这次,他们证明…...

【JavaSE专栏58】“Java构造函数:作用、类型、调用顺序和最佳实践“ ⚙️⏱️
解析Java构造函数:作用、类型、调用顺序和最佳实践" 🚀📚🔍🤔📝🔄⚙️⏱️📖🌐 摘要引言1. 什么是构造函数 🤔2. 构造函数的类型与用途 📝1.…...

Ubuntu系统HUSTOJ 用 vim 修改php.ini 重启PHP服务
cd / sudo find -name php.ini 输出: ./etc/php/7.4/cli/php.ini ./etc/php/7.4/fpm/php.ini sudo vim /etc/php/7.4/cli/php.ini sudo vim /etc/php/7.4/fpm/php.ini 知识准备: vim的搜索与替换 在正常模式下键入 / ,即可进入搜索模式…...

案例分析真题-信息安全
案例分析真题-信息安全 2009年真题 【问题1】 【问题2】 【问题3】 2010年真题 【问题1】 【问题2】 【问题3】 2011 年真题 【问题1】 【问题2】 【问题3】 骚戴理解:这个破题目完全考的知识储备,不知道的连手都动不了,没法分析 2013年真题…...

envi5.3处理高分二号影像数据辐射定标大气校正
目录 一、多光谱影像处理 1. 辐射定标 2.大气校正 1. 需要准备一些数据: 2.大气校正过程 3、正射校正 二、全色影像处理 1. 辐射定标 2. 正射校正 三、图像融合 1.几何配准 2.图像融合 高分二号处理流程 envi5.3的安装教程: ENVI5.3安装 安装完ENVI5.3后࿰…...

C语言 结构体
结构体的自引用: 自引用的目的: 结构体的自引用就是指在结构体内部,包含指向自身类型结构体的指针。 像链表就会用到结构体的自引用。假如我们要创建链表 链表的没个节点都是一个结构体,它里面存放着它的数据和下个节点的地址。 假如我们用…...

frp-内网穿透部署-ubuntu22服务器-windows server-详细教程
文章目录 1.下载frp2.配置服务器2.1.配置frps.ini文件2.2.设置服务文件2.3.设置开机自启和服务操作2.4.后台验证2.5.服务器重启 3.配置本地window3.1.frpc配置3.2.添加开机计划启动3.3.控制台启动隐藏窗口 4.centos防火墙和端口3.1.开放端口3.2.查看端口 5.关闭进程5.1.杀死进程…...
MySQL内存使用的监控开关和使用查看
参考文档: https://brands.cnblogs.com/tencentcloud/p/11151 https://www.cnblogs.com/grasp/p/10306697.html MySQL如何使用内存 在MySQL中,内存占用主要包括以下几部分,全局共享的内存、线程独占的内存、内存分配器占用的内存࿰…...

数据库管理-第113期 Oracle Exadata 04-硬件选择(20231020)
数据库管理-第113期 Oracle Exadata 04-硬件选择(2023010290) 本周没写文章,主要是因为到上海参加了Oracle CAB/PAB会议,这个放在后面再讲,本期讲一讲Exadata,尤其是存储节点的硬件选择及其对应的一些通用…...

带着问题去分析:Spring Bean 生命周期 | 京东物流技术团队
1: Bean在Spring容器中是如何存储和定义的 Bean在Spring中的定义是_org.springframework.beans.factory.config.BeanDefinition_接口,BeanDefinition里面存储的就是我们编写的Java类在Spring中的元数据,包括了以下主要的元数据信息: 1&…...
C语言修行之函数篇(一)tolower —— 转换为小写字母
文章目录 函数说明函数声明函数返回值函数实现函数实例 函数说明 对于大写字母,如果在当前语言环境中存在小写表示形式,则tolower()返回其小写等效物。否则,tolower()函数执行相同的任务。 函数声明 #include <ctype.h> int tolower(…...

【JavaSE专栏55】Java集合类HashTable解析
🌲Java集合类HashTable解析 🌲Java集合类HashTable解析摘要引言Hashtable是什么?Hashtable vs. HashMap:何时使用Hashtable?多线程环境:历史遗留系统:不需要进行特殊操作: Hashtable…...

Apollo上机实践:一次对自动驾驶技术的亲身体验
上机实践 概述自动驾驶通信分布式系统开发模式开发工具 自动驾驶感知传感器特性感知流程及算法部署感知模型 自动驾驶决策规划决策规划流程和算法使用 Dreamview 进行控制在环的规划调试开发规划场景和算法 福利活动 主页传送门:📀 传送 概述 Apollo 是…...
QTcpServer简单的TCP服务器连接
1、简介 简单实现控制TCP服务器获取连接的套接字。点击断开服务器即可关闭所有连接,最大连接数量为5个。 声明源文件 #include "mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) {//设置固定大小setFixedSize(1024,600);b…...

LeetCode热题100——双指针
双指针 1.移动零2.盛最多水的容器3.三数之和 1.移动零 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 // 题解:使用双指针,其中快指针指向非零元素,慢指针指向首个零元素下…...

Ubuntu ARMv8编译Qt源码以及QtCreator
最近需要在NVIDIA小盒子上面跑一个程序,一开始想着在Ubuntu x64下交叉编译一版,后来发现libqxcb.so 这个库在configure时就会一直报错,多方查找怀疑可能是由于硬件不支持在x64环境下编译AMR架构的xcb库。 所以最后在ARM下直接编译Qt源码了&am…...
虚机Centos忘记密码如何重置
1进入开机前的页面,选中第一个,按“e”键,进入编辑模式 2找到ro crashkernel项,将ro替换成 rw initsysroot/bin/sh 3 Ctrlx mount -o remount, rw / chroot /sysroot chroot /sysroot passwd root 输入两次密码 touch /.a…...
OpenGL_Learn02
1. 监听窗口,绑定回调函数 #include <glad/glad.h> #include <GLFW/glfw3.h> #include <iostream>void framebuffer_size_callback(GLFWwindow* window, int width, int height) {glViewport(0, 0, width, height);std::cout << "变了…...

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...
基于大模型的 UI 自动化系统
基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...
Rust 异步编程
Rust 异步编程 引言 Rust 是一种系统编程语言,以其高性能、安全性以及零成本抽象而著称。在多核处理器成为主流的今天,异步编程成为了一种提高应用性能、优化资源利用的有效手段。本文将深入探讨 Rust 异步编程的核心概念、常用库以及最佳实践。 异步编程基础 什么是异步…...
【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的“no matching...“系列算法协商失败问题
【SSH疑难排查】轻松解决新版OpenSSH连接旧服务器的"no matching..."系列算法协商失败问题 摘要: 近期,在使用较新版本的OpenSSH客户端连接老旧SSH服务器时,会遇到 "no matching key exchange method found", "n…...
人工智能 - 在Dify、Coze、n8n、FastGPT和RAGFlow之间做出技术选型
在Dify、Coze、n8n、FastGPT和RAGFlow之间做出技术选型。这些平台各有侧重,适用场景差异显著。下面我将从核心功能定位、典型应用场景、真实体验痛点、选型决策关键点进行拆解,并提供具体场景下的推荐方案。 一、核心功能定位速览 平台核心定位技术栈亮…...

C++_哈希表
本篇文章是对C学习的哈希表部分的学习分享 相信一定会对你有所帮助~ 那咱们废话不多说,直接开始吧! 一、基础概念 1. 哈希核心思想: 哈希函数的作用:通过此函数建立一个Key与存储位置之间的映射关系。理想目标:实现…...

Linux基础开发工具——vim工具
文章目录 vim工具什么是vimvim的多模式和使用vim的基础模式vim的三种基础模式三种模式的初步了解 常用模式的详细讲解插入模式命令模式模式转化光标的移动文本的编辑 底行模式替换模式视图模式总结 使用vim的小技巧vim的配置(了解) vim工具 本文章仍然是继续讲解Linux系统下的…...

Linux【5】-----编译和烧写Linux系统镜像(RK3568)
参考:讯为 1、文件系统 不同的文件系统组成了:debian、ubuntu、buildroot、qt等系统 每个文件系统的uboot和kernel是一样的 2、源码目录介绍 目录 3、正式编译 编译脚本build.sh 帮助内容如下: Available options: uboot …...

【动态规划】B4336 [中山市赛 2023] 永别|普及+
B4336 [中山市赛 2023] 永别 题目描述 你做了一个梦,梦里有一个字符串,这个字符串无论正着读还是倒着读都是一样的,例如: a b c b a \tt abcba abcba 就符合这个条件。 但是你醒来时不记得梦中的字符串是什么,只记得…...

设计模式-3 行为型模式
一、观察者模式 1、定义 定义对象之间的一对多的依赖关系,这样当一个对象改变状态时,它的所有依赖项都会自动得到通知和更新。 描述复杂的流程控制 描述多个类或者对象之间怎样互相协作共同完成单个对象都无法单独度完成的任务 它涉及算法与对象间职责…...