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

[JavaWeb]【八】web后端开发-Mybatis

目录

一 介绍

二 Mybatis的入门

2.1 快速入门

 2.1.1 准备SpringBoot工程

2.1.2 创建数据库mybatis以及对应库表user

2.1.3 创建User实体类

 2.1.4 配置application.properties数据库连接信息

2.1.5 编写sql语句(注解方式)

2.1.6 测试运行 

 2.1.7 配置SQL提示

2.2 JDBC介绍(了解)

2.2.1 JDBC 介绍

2.2.2 jdbc与Mybatis对比

2.3 数据库连接池(了解)

2.3.1 概念

2.3.2 mybatis切换Druid(德鲁伊)连接池

 2.3.3 总结

2.4 lombok

三 Mybatis的基础操作

3.1 准备工作

3.1.1 数据脚本在mybatis表执行脚本

3.1.2 创建一个springboot项目 

3.1.3 application.properties配置

3.1.4 创建对应实体类Emp

3.1.5 准备Mapper接口EmpMapper

3.2 日志输出

3.2.1 性能高 

 3.2.2 更安全

 3.2.3 总结 使用#

3.3 删除

 3.3.1 EmpMapper接口添加 删除方法

3.3.2 新增测试方法

3.4 新增

3.4.1 EmpMapper接口添加 新增方法

3.4.2 新增测试方法 

3.4.3 主键返回

3.4.4 总结 

3.5 更新

3.5.1 EmpMapper接口添加 更新方法

3.5.2 新增测试方法

3.6 查询

3.6.1 EmpMapper接口添加 查询方法

3.6.2 新增测试方法

3.6.3 数据封装

 3.6.3.1 方案一 (不推荐):当数据库字段与实体类字段不一致时取别名

3.6.3.2 方案二(不推荐) :通过@Results, @Result注解手动映射封装

 3.6.3.3 方案三(推荐):开启mybatis的驼峰命名自动映射开关

3.7 查询(条件查询)

3.7.1 EmpMapper接口添加 条件查询方法

3.7.2 新增测试方法

 3.7.3 使用concat解决使用'%$name}%'问题

四 XML映射文件

4.1 XML映射规范

4.1.1 第一步: 

 4.1.2 第二步:​编辑

4.1.3 第三步

4.1.4 验证

 4.2 mybatisx插件

4.3 总结

五 Mybatis的动态SQL

5.1

5.1.1 优化EmpMapper.xml

 5.1.2 案例

5.1.2.1 优化EmpMapper 新增一个方法update2

5.1.2.2 EmpMpapper.xml新增一个update2的sql 

5.1.2.3 新增测试方法testUpdate2测试

​编辑5.1.3 总结

5.2

5.2.1 优化EmpMapper 新增一个方法deleteByIds

5.2.2 EmpMpapper.xml新增一个deleteByIds的sql 

5.2.3 新增测试方法testDeleteByids

 5.2.4 总结

5.3

 5.3.1 EmpMpapper.xml新增sql 标签优化list2 include标签 

5.3.2 执行测试方法testList2

5.4 总结 


前言:Mybatis数据持久层,进行数据库操作,增删改查 ,动态sql

一 介绍

二 Mybatis的入门

2.1 快速入门

案例

 2.1.1 准备SpringBoot工程

 

2.1.2 创建数据库mybatis以及对应库表user

create database mybatis;
create table user(id int unsigned primary key auto_increment comment 'ID',name varchar(100) comment '姓名',age tinyint unsigned comment '年龄',gender tinyint unsigned comment '性别, 1:男, 2:女',phone varchar(11) comment '手机号'
) comment '用户表';insert into user(id, name, age, gender, phone) VALUES (null,'白眉鹰王',55,'1','18800000000');
insert into user(id, name, age, gender, phone) VALUES (null,'金毛狮王',45,'1','18800000001');
insert into user(id, name, age, gender, phone) VALUES (null,'青翼蝠王',38,'1','18800000002');
insert into user(id, name, age, gender, phone) VALUES (null,'紫衫龙王',42,'2','18800000003');
insert into user(id, name, age, gender, phone) VALUES (null,'光明左使',37,'1','18800000004');
insert into user(id, name, age, gender, phone) VALUES (null,'光明右使',48,'1','18800000005');

2.1.3 创建User实体类

package com.runa.pojo;public class User {private Integer id;private String name;private Short age;private Short gender;private String phone;public User() {}public User(Integer id, String name, Short age, Short gender, String phone) {this.id = id;this.name = name;this.age = age;this.gender = gender;this.phone = phone;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Short getAge() {return age;}public void setAge(Short age) {this.age = age;}public Short getGender() {return gender;}public void setGender(Short gender) {this.gender = gender;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}@Overridepublic String toString() {return "User{" +"id=" + id +", name='" + name + '\'' +", age=" + age +", gender=" + gender +", phone='" + phone + '\'' +'}';}
}

 2.1.4 配置application.properties数据库连接信息

# 配置数据库连接信息
#驱动类名称
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#数据库连接的url
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
#连接数据库的用户名
spring.datasource.username=root
#连接数据库的密码
spring.datasource.password=1234
package com.runa.pojo;public class User {private Integer id;private String name;private Short age;private Short gender;private String phone;public User(Integer id, String name, Short age, Short gender, String phone) {this.id = id;this.name = name;this.age = age;this.gender = gender;this.phone = phone;}public User() {}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Short getAge() {return age;}public void setAge(Short age) {this.age = age;}public Short getGender() {return gender;}public void setGender(Short gender) {this.gender = gender;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}@Overridepublic String toString() {return "User{" +"id=" + id +", name='" + name + '\'' +", age=" + age +", gender=" + gender +", phone='" + phone + '\'' +'}';}
}

2.1.5 编写sql语句(注解方式)

package com.runa.mapper;import com.runa.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;import java.util.List;@Mapper  // 运行时,会自动生成该接口的实现类对象(代理对象),并且将改对象交给IOC容器管理
public interface UserMapper {// 查询全部用户信息@Select("select * from user")public List<User> list();
}

2.1.6 测试运行 

package com.runa;import com.runa.mapper.UserMapper;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {@Autowired  // 注入private UserMapper userMapper;@Testpublic void testListUser() {List<User> userList = userMapper.list();userList.stream().forEach(user -> {System.out.println(user);});}//    @Test
//    void contextLoads() {
//    }}

 

 2.1.7 配置SQL提示

 设置好,还不行的话(删除其他数据库连接,刷新数据库连接),重启IEDA

2.2 JDBC介绍(了解)

2.2.1 JDBC 介绍

@Testpublic void testJdbc() throws Exception {//1 注册驱动Class.forName("com.mysql.cj.jdbc.Driver");// 2 获取连接对象String url = "jdbc:mysql://localhost:3306/mybatis";String username = "root";String password = "runa#2050";Connection  connection = DriverManager.getConnection(url, username, password);// 3 获取执行sql的对象statement,执行sql 返回结果String sql = "select * from user";Statement statement = null;statement = connection.createStatement();ResultSet resultSet = null;resultSet = statement.executeQuery(sql);// 4 封装结果数据List<User> userList = new ArrayList<>();while (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");short age = resultSet.getShort("age");short gender = resultSet.getShort("gender");String phone = resultSet.getString("phone");User  user = new User(id, name, age, gender, phone);userList.add(user);}// 5 释放资源statement.close();connection.close();userList.stream().forEach(user -> {System.out.println(user);});}

 

 

2.2.2 jdbc与Mybatis对比

 

 

 

2.3 数据库连接池(了解)

2.3.1 概念

 

 

2.3.2 mybatis切换Druid(德鲁伊)连接池

 我没有配置成功

 2.3.3 总结

 

2.4 lombok

 

 

 添加依赖

    <dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency>

修改实体类User

package com.runa.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {private Integer id;private String name;private Short age;private Short gender;private String phone;}

 

三 Mybatis的基础操作

3.1 准备工作

 

 

3.1.1 数据脚本在mybatis表执行脚本

-- 部门管理
create table dept(id int unsigned primary key auto_increment comment '主键ID',name varchar(10) not null unique comment '部门名称',create_time datetime not null comment '创建时间',update_time datetime not null comment '修改时间'
) comment '部门表';insert into dept (id, name, create_time, update_time) values(1,'学工部',now(),now()),(2,'教研部',now(),now()),(3,'咨询部',now(),now()), (4,'就业部',now(),now()),(5,'人事部',now(),now());-- 员工管理
create table emp (id int unsigned primary key auto_increment comment 'ID',username varchar(20) not null unique comment '用户名',password varchar(32) default '123456' comment '密码',name varchar(10) not null comment '姓名',gender tinyint unsigned not null comment '性别, 说明: 1 男, 2 女',image varchar(300) comment '图像',job tinyint unsigned comment '职位, 说明: 1 班主任,2 讲师, 3 学工主管, 4 教研主管, 5 咨询师',entrydate date comment '入职时间',dept_id int unsigned comment '部门ID',create_time datetime not null comment '创建时间',update_time datetime not null comment '修改时间'
) comment '员工表';INSERT INTO emp(id, username, password, name, gender, image, job, entrydate,dept_id, create_time, update_time) VALUES(1,'jinyong','123456','金庸',1,'1.jpg',4,'2000-01-01',2,now(),now()),(2,'zhangwuji','123456','张无忌',1,'2.jpg',2,'2015-01-01',2,now(),now()),(3,'yangxiao','123456','杨逍',1,'3.jpg',2,'2008-05-01',2,now(),now()),(4,'weiyixiao','123456','韦一笑',1,'4.jpg',2,'2007-01-01',2,now(),now()),(5,'changyuchun','123456','常遇春',1,'5.jpg',2,'2012-12-05',2,now(),now()),(6,'xiaozhao','123456','小昭',2,'6.jpg',3,'2013-09-05',1,now(),now()),(7,'jixiaofu','123456','纪晓芙',2,'7.jpg',1,'2005-08-01',1,now(),now()),(8,'zhouzhiruo','123456','周芷若',2,'8.jpg',1,'2014-11-09',1,now(),now()),(9,'dingminjun','123456','丁敏君',2,'9.jpg',1,'2011-03-11',1,now(),now()),(10,'zhaomin','123456','赵敏',2,'10.jpg',1,'2013-09-05',1,now(),now()),(11,'luzhangke','123456','鹿杖客',1,'11.jpg',5,'2007-02-01',3,now(),now()),(12,'hebiweng','123456','鹤笔翁',1,'12.jpg',5,'2008-08-18',3,now(),now()),(13,'fangdongbai','123456','方东白',1,'13.jpg',5,'2012-11-01',3,now(),now()),(14,'zhangsanfeng','123456','张三丰',1,'14.jpg',2,'2002-08-01',2,now(),now()),(15,'yulianzhou','123456','俞莲舟',1,'15.jpg',2,'2011-05-01',2,now(),now()),(16,'songyuanqiao','123456','宋远桥',1,'16.jpg',2,'2010-01-01',2,now(),now()),(17,'chenyouliang','123456','陈友谅',1,'17.jpg',NULL,'2015-03-21',NULL,now(),now());

3.1.2 创建一个springboot项目 

引入起步依赖mybatis、mysql驱动、lombok

3.1.3 application.properties配置

指定mybatis输出日志的位置。输出控制台

# 配置数据库连接
# 驱动类名称
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 连接数据库的url
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
#连接数据库用户名
spring.datasource.username=root
# 连接数据库密码
spring.datasource.password=runa#2050# 指定mybatis输出日志的位置。输出控制台
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

3.1.4 创建对应实体类Emp

package com.runa.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.time.LocalDateTime;@Data
@NoArgsConstructor
@AllArgsConstructor
public class Emp {private Integer id;private String username;private String password;private String name;private Short gender;private String image;private Short job;private LocalDate entrydate;private Integer deptId;private LocalDateTime createTime;private LocalDateTime updateTime;
}

 

3.1.5 准备Mapper接口EmpMapper

 

package com.runa.mapper;import org.apache.ibatis.annotations.Mapper;@Mapper
public interface EmpMapper {
}

3.2 日志输出

3.2.1 性能高 

 

 

 3.2.2 更安全

 

 3.2.3 总结 使用#

 

 

3.3 删除

 

 3.3.1 EmpMapper接口添加 删除方法

package com.runa.mapper;import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);
}

3.3.2 新增测试方法

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {@Autowired //注入private EmpMapper empMapper;@Testpublic void testDelete(){empMapper.delete(17);}}

改造一下获取返回值

package com.runa.mapper;import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface EmpMapper {// 根据id删除数据
//    @Delete("delete from emp where id = #{id}")
//    public void delete(Integer id);// 根据id删除数据,并获取返回值@Delete("delete from emp where id = #{id}")public int delete(Integer id);
}
package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }//    @Test
//    public void testDelete(){
//        empMapper.delete(17);
//
//    }@Test  // 获取返回值public void testDelete(){int id = empMapper.delete(16);System.out.println(id);}}

 

 

 返回 1表示删除成功,0 是失败

 

3.4 新增

 

3.4.1 EmpMapper接口添加 新增方法

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Insert("insert into emp\n" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);}

3.4.2 新增测试方法 

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai");emp.setName("菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);}}

 

 

3.4.3 主键返回

 

3.4.4 总结 

 

3.5 更新

 

3.5.1 EmpMapper接口添加 更新方法

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);}

3.5.2 新增测试方法

 

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}}

3.6 查询

 

3.6.1 EmpMapper接口添加 查询方法

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);// 根据ID查询员工@Select("select * from emp where id = #{id}")public Emp getById(Integer id);}

3.6.2 新增测试方法

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }// 测试新增@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}// 测试更新@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}// 根据员工ID查询员工@Testpublic void testGetById(){Emp emp = empMapper.getById(19);System.out.println(emp);}}

 

3.6.3 数据封装

 3.6.3.1 方案一 (不推荐):当数据库字段与实体类字段不一致时取别名

 修改Empmapper接口类

    // 根据ID查询员工
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工,取别名方案@Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")public Emp getById(Integer id);

 

3.6.3.2 方案二(不推荐) :通过@Results, @Result注解手动映射封装

   // 根据ID查询员工
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工,方案一:取别名方案
//    @Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工 方案二:通过@Results, @Result注解手动映射封装@Results({@Result(column = "dept_id", property = "deptId"),@Result(column = "create_time", property = "createTime"),@Result(column = "update_time", property = "updateTime")})@Select("select * from emp where id = #{id}")public Emp getById(Integer id);

 

 3.6.3.3 方案三(推荐):开启mybatis的驼峰命名自动映射开关

application.properties新增配置

# 配置数据库连接
# 驱动类名称
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 连接数据库的url
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
#连接数据库用户名
spring.datasource.username=root
# 连接数据库密码
spring.datasource.password=runa#2050# 指定mybatis输出日志的位置。输出控制台
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl# # 开启mybatis的驼峰命名自动映射开关
mybatis.configuration.map-underscore-to-camel-case=true

 

 

插曲:IDEA 的application.properties中文乱码,

配置前:

 修改后:

 

 

 

3.7 查询(条件查询)

 ​​​​​​​​​​​​​​

 

 

 

3.7.1 EmpMapper接口添加 条件查询方法

'%#{name}%' #{name}  不能出现在''里面所以改成$

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);// 根据ID查询员工@Select("select * from emp where id = #{id}")public Emp getById(Integer id);// 根据ID查询员工, (不推荐)方案一:取别名方案
//    @Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工 (不推荐)方案二:通过@Results, @Result注解手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 条件查询员工  '%#{name}%' #{name}  不能出现在''里面所以改成$@Select("select * from emp where name like '%${name}%'and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);}

3.7.2 新增测试方法

 

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }// 测试新增@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}// 测试更新@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}// 根据员工ID查询员工@Testpublic void testGetById(){Emp emp = empMapper.getById(19);System.out.println(emp);}// 条件查询@Testpublic void testList(){List<Emp> listEmp = empMapper.list("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(listEmp);}}

 

 3.7.3 使用concat解决使用'%$name}%'问题

修改EmpMapper接口

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);// 根据ID查询员工@Select("select * from emp where id = #{id}")public Emp getById(Integer id);// 根据ID查询员工, (不推荐)方案一:取别名方案
//    @Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工 (不推荐)方案二:通过@Results, @Result注解手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 条件查询员工  '%#{name}%' #{name}  不能出现在''里面所以改成$
//    @Select("select * from emp where name like '%${name}%'and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")
//    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);// 条件查询员工 使用concat解决 '%${name}%'@Select("select * from emp where name like concat('%', #{name}, '%')and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);}

 以下图片可忽略

四 XML映射文件

4.1 XML映射规范

4.1.1 第一步: 

 

EmpMapper.xml文件如下: 

<?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></mapper>

 4.1.2 第二步:

 

<?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.runa.mapper.EmpMapper"></mapper>

4.1.3 第三步

resultType : 表示单条记录所封装的类型

 

<?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.runa.mapper.EmpMapper"><!--id EmpMapper 方法名   resultType : 表示单条记录所封装的类型  --><select id="list2" resultType="com.runa.pojo.Emp">select * from emp where name like concat('%', #{name}, '%')and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc</select></mapper>

4.1.4 验证

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }// 测试新增@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}// 测试更新@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}// 根据员工ID查询员工@Testpublic void testGetById(){Emp emp = empMapper.getById(19);System.out.println(emp);}// 条件查询@Testpublic void testList(){List<Emp> listEmp = empMapper.list("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(listEmp);}// 条件查询 使用xml@Testpublic void testList2(){List<Emp> listEmp = empMapper.list2("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(listEmp);}}

 

 4.2 mybatisx插件

 快速定位

 

4.3 总结

 

 

五 Mybatis的动态SQL

5.1 <if>

5.1.1 优化EmpMapper.xml

<?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.runa.mapper.EmpMapper"><!--id EmpMapper 方法名   resultType : 表示单条记录所封装的类型  --><select id="list2" resultType="com.runa.pojo.Emp">select *from emp<where><if test= "name != null">name like concat('%', #{name}, '%')</if><if test= "gender != null">and gender = #{gender}</if><if test= "begin != null and end != null">and entrydate between #{begin} and #{end}</if>order by update_time desc</where></select></mapper>

 

 

 

 注意:<where></where> 会针对多条件查询过滤一些特有的and

 5.1.2 案例

 

 

5.1.2.1 优化EmpMapper 新增一个方法update2

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);// 根据ID查询员工@Select("select * from emp where id = #{id}")public Emp getById(Integer id);// 根据ID查询员工, (不推荐)方案一:取别名方案
//    @Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工 (不推荐)方案二:通过@Results, @Result注解手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 条件查询员工  '%#{name}%' #{name}  不能出现在''里面所以改成$
//    @Select("select * from emp where name like '%${name}%'and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")
//    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);// 条件查询员工 使用concat解决 '%${name}%'@Select("select * from emp where name like concat('%', #{name}, '%')and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);// 条件查询员工使用xml方式public List<Emp> list2(String name, Short gender, LocalDate begin, LocalDate end);// 更新员工信息使用xml方式 使用<if>,使用动态sql方式public void update2(Emp emp);}

5.1.2.2 EmpMpapper.xml新增一个update2的sql 

这里也使用了<set></set>标签

<?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.runa.mapper.EmpMapper"><!--id EmpMapper 方法名   resultType : 表示单条记录所封装的类型  --><select id="list2" resultType="com.runa.pojo.Emp">select *from emp<where><if test="name != null">name like concat('%', #{name}, '%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if>order by update_time desc</where></select><!-- 动态更新员工--><update id="update2">update emp <set><if test="username != null">username = #{username},</if><if test="name != null">name= #{name},</if><if test="gender != null">gender = #{gender},</if><if test="image != null">image = #{image},</if><if test="job != null">job = #{job},</if><if test="entrydate != null">entrydate = #{entrydate},</if><if test="deptId != null">dept_id = #{deptId},</if><if test="updateTime != null">update_time = #{updateTime}</if></set>where id=#{id}</update></mapper>

5.1.2.3 新增测试方法testUpdate2测试

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }// 测试新增@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}// 测试更新@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}// 根据员工ID查询员工@Testpublic void testGetById(){Emp emp = empMapper.getById(19);System.out.println(emp);}// 条件查询@Testpublic void testList(){List<Emp> listEmp = empMapper.list("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(listEmp);}// 条件查询 使用xml@Testpublic void testList2(){
//        List<Emp> listEmp = empMapper.list2("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));List<Emp> listEmp = empMapper.list2("张", (short) 1, null, null);System.out.println(listEmp);}// 测试更新,使用动态sql 更新id为18的员工username bocai2 更新为  name菠菜大哥 更新为 gender更新为 2@Testpublic void testUpdate2(){// 构造员工对象Emp emp = new Emp();emp.setId(18);emp.setUsername("bocai2");emp.setName("菠菜大哥");emp.setDeptId(2);emp.setUpdateTime(LocalDateTime.now());// 执行更新员工的信息操作empMapper.update2(emp);}}

5.1.3 总结

 

5.2 <foreach>

5.2.1 优化EmpMapper 新增一个方法deleteByIds

package com.runa.mapper;import com.runa.pojo.Emp;
import org.apache.ibatis.annotations.*;import java.time.LocalDate;
import java.util.List;@Mapper
public interface EmpMapper {// 根据id删除数据@Delete("delete from emp where id = #{id}")public void delete(Integer id);// 根据id删除数据,并获取返回值
//    @Delete("delete from emp where id = #{id}")
//    public int delete(Integer id);// 新增员工@Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into emp" +"(username, name, gender, image, job, entrydate,dept_id, create_time, update_time)" +" VALUES(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")public void insert(Emp emp);// 更新员工信息@Update("update emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, " +"job = #{job}, entrydate = #{entrydate},dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")public void update(Emp emp);// 根据ID查询员工@Select("select * from emp where id = #{id}")public Emp getById(Integer id);// 批量删除员工public void deleteByIds(List<Integer> ids);// 根据ID查询员工, (不推荐)方案一:取别名方案
//    @Select("select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);// 根据ID查询员工 (不推荐)方案二:通过@Results, @Result注解手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp getById(Integer id);// 条件查询员工  '%#{name}%' #{name}  不能出现在''里面所以改成$
//    @Select("select * from emp where name like '%${name}%'and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")
//    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);// 条件查询员工 使用concat解决 '%${name}%'@Select("select * from emp where name like concat('%', #{name}, '%')and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc ")public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);// 条件查询员工使用xml方式public List<Emp> list2(String name, Short gender, LocalDate begin, LocalDate end);// 更新员工信息使用xml方式 使用<if>,使用动态sql方式public void update2(Emp emp);}

5.2.2 EmpMpapper.xml新增一个deleteByIds的sql 

<?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.runa.mapper.EmpMapper"><!--id EmpMapper 方法名   resultType : 表示单条记录所封装的类型  --><select id="list2" resultType="com.runa.pojo.Emp">select *from emp<where><if test="name != null">name like concat('%', #{name}, '%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if>order by update_time desc</where></select><!-- 动态更新员工--><update id="update2">update emp<set><if test="username != null">username = #{username},</if><if test="name != null">name= #{name},</if><if test="gender != null">gender = #{gender},</if><if test="image != null">image = #{image},</if><if test="job != null">job = #{job},</if><if test="entrydate != null">entrydate = #{entrydate},</if><if test="deptId != null">dept_id = #{deptId},</if><if test="updateTime != null">update_time = #{updateTime}</if></set>where id=#{id}</update><!--    批量删除员工 (18,19,20)--><!--collection : 要遍历的集合item : 遍历出来的元素separator : 分隔符open :遍历开始前拼接的sql片段close : 遍历结束后拼接的sql片段)--><delete id="deleteByIds">delete from emp where id in<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach></delete>
</mapper>

5.2.3 新增测试方法testDeleteByids

 

package com.runa;import com.runa.mapper.EmpMapper;
import com.runa.mapper.UserMapper;
import com.runa.pojo.Emp;
import com.runa.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {//    @Autowired  // 注入
//    private UserMapper userMapper;@Autowired //注入private EmpMapper empMapper;//    @Test
//    public void testListUser() {
//        List<User> userList = userMapper.list();
//        userList.stream().forEach(user -> {
//            System.out.println(user);
//        });
//    }@Testpublic void testDelete(){empMapper.delete(17);}//    @Test  // 获取返回值
//    public void testDelete(){
//        int id = empMapper.delete(16);
//        System.out.println(id);
//    }// 测试新增@Testpublic void testInsert(){// 构造员工对象Emp emp = new Emp();emp.setUsername("Bocai1");emp.setName("菠菜1");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setCreateTime(LocalDateTime.now());emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行新增员工的信息操作empMapper.insert(emp);System.out.println(emp.getId());}// 测试更新@Testpublic void testUpdate(){// 构造员工对象Emp emp = new Emp();emp.setId(19);emp.setUsername("Spring");emp.setName("春天的菠菜");emp.setImage("1.jpg");emp.setGender((short)1);emp.setJob((short)1);emp.setEntrydate(LocalDate.of(2023, 2,27));emp.setUpdateTime(LocalDateTime.now());emp.setDeptId(1);// 执行更新员工的信息操作empMapper.update(emp);}// 根据员工ID查询员工@Testpublic void testGetById(){Emp emp = empMapper.getById(19);System.out.println(emp);}// 条件查询@Testpublic void testList(){List<Emp> listEmp = empMapper.list("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(listEmp);}// 条件查询 使用xml@Testpublic void testList2(){
//        List<Emp> listEmp = empMapper.list2("张", (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));List<Emp> listEmp = empMapper.list2("张", (short) 1, null, null);System.out.println(listEmp);}// 测试更新,使用动态sql 更新id为18的员工username bocai2 更新为  name菠菜大哥 更新为 gender更新为 2@Testpublic void testUpdate2(){// 构造员工对象Emp emp = new Emp();emp.setId(18);emp.setUsername("bocai2");emp.setName("菠菜大哥");emp.setDeptId(2);emp.setUpdateTime(LocalDateTime.now());// 执行更新员工的信息操作empMapper.update2(emp);}// 批量删除员工 13 、 14、  15@Testpublic void testDeleteByids(){List<Integer> ids = Arrays.asList(13, 14, 15);empMapper.deleteByIds(ids);}}

 

 

 

 5.2.4 总结

 

5.3 <sql><include>

存在大量重复的sql

解决方案

 

 

 5.3.1 EmpMpapper.xml新增sql 标签优化list2 include标签 

<?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.runa.mapper.EmpMapper"><sql id="commonSelect">select id,id, username, password, name, gender, image, job, entrydate, dept_id deptId, create_time createTime, update_time updateTime from emp</sql><!--id EmpMapper 方法名   resultType : 表示单条记录所封装的类型  --><select id="list2" resultType="com.runa.pojo.Emp"><include refid="commonSelect"></include><where><if test="name != null">name like concat('%', #{name}, '%')</if><if test="gender != null">and gender = #{gender}</if><if test="begin != null and end != null">and entrydate between #{begin} and #{end}</if>order by update_time desc</where></select><!-- 动态更新员工--><update id="update2">update emp<set><if test="username != null">username = #{username},</if><if test="name != null">name= #{name},</if><if test="gender != null">gender = #{gender},</if><if test="image != null">image = #{image},</if><if test="job != null">job = #{job},</if><if test="entrydate != null">entrydate = #{entrydate},</if><if test="deptId != null">dept_id = #{deptId},</if><if test="updateTime != null">update_time = #{updateTime}</if></set>where id=#{id}</update><!--    批量删除员工 (18,19,20)--><!--collection : 要遍历的集合item : 遍历出来的元素separator : 分隔符open :遍历开始前拼接的sql片段close : 遍历结束后拼接的sql片段)--><delete id="deleteByIds">delete from emp where id in<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach></delete>
</mapper>

5.3.2 执行测试方法testList2

 

5.4 总结 

 

相关文章:

[JavaWeb]【八】web后端开发-Mybatis

目录 一 介绍 二 Mybatis的入门 2.1 快速入门 2.1.1 准备SpringBoot工程 2.1.2 创建数据库mybatis以及对应库表user 2.1.3 创建User实体类 2.1.4 配置application.properties数据库连接信息 2.1.5 编写sql语句&#xff08;注解方式&#xff09; 2.1.6 测试运行 2.1.7 配…...

Flink源码之Checkpoint执行流程

Checkpoint完整流程如上图所示&#xff1a; JobMaster的CheckpointCoordinator向所有SourceTask发送RPC触发一次CheckPointSourceTask向下游广播CheckpointBarrierSouceTask完成状态快照后向JobMaster发送快照结果非SouceTask在Barrier对齐后完成状态快照向JobMaster发送快照结…...

【工具使用】Git的使用

dev代表开发版 1. git clone 命令 通过 git add <name> 对文件进行跟踪&#xff0c;把<name>加入到暂存区 git commit -m XXXXXXX 提交修改并补充XXXXX作为注释 “暂存”状态&#xff1a;出现了一些修改&#xff0c;但是还没有提交 对于Java来说&#xff0c;.cl…...

无涯教程-PHP Installation on Windows NT/2000/XP with IIS函数

在Windows Server上运行IIS的PHP的安装比在Unix上简单得多,因为它涉及的是预编译的二进制文件而不是源代码。 如果您打算在Windows上安装PHP,那么这是先决条件列表- 运行中的PHP支持的Web服务器。一个正确安装的PHP支持的数据库,如MySQL或Oracle等。(如果您打算使用的话) PHP…...

EureKa快速入门

EureKa快速入门 远程调用的问题 多个服务有多个端口&#xff0c;这样的话服务有多个&#xff0c;硬编码不太适合 eureKa的作用 将service的所有服务的端口全部记录下来 想要的话 直接从注册中心查询对于所有服务 每隔一段时间需要想eureKa发送请求 保证服务还存活 动手实践 …...

Sectigo EV代码签名申请步骤

一、EV代码签名申请前提 1、单位成立时间不低于&#xff1a;3个月 2、单位工商及企查查可查 3、单位经营正常 4、注册地址真实存在&#xff0c;禁止使用集中注册地址 5、企查查登记电话和邮箱&#xff0c;确定查询结果的电话可以接听、邮箱可以接收邮件&#xff0c;如果信…...

生信学院|08月25日《SOLIDWORKS PDM帮助企业对设计数据版本的管理应用》

课程主题&#xff1a;SOLIDWORKS PDM帮助企业对设计数据版本的管理应用 课程时间&#xff1a;2023年08月25日 14:00-14:30 主讲人&#xff1a;车立洋 生信科技 PDM专家 1、图纸&文档的版本管理对于企业的重要性 2、SolidWorks PDM对图纸&文档版本的管理 3、SolidW…...

vue页面转pdf后分页时文字被横向割裂

效果 预期效果 //避免分页被截断async outPutPdfFn (id, title) {const _t this;const A4_WIDTH 592.28;const A4_HEIGHT 841.89;// dom的id。let target document.getElementById(pdf);let pageHeight target.scrollWidth / A4_WIDTH * A4_HEIGHT;// 获取分割dom&#xf…...

数据结构——队列(C语言)

需求&#xff1a;无 本篇文章将解决一下几个问题&#xff1a; 队列是什么&#xff1f;如何实现一个队列&#xff1f;什么场景下会用队列&#xff1f; 队列的概念&#xff1a; 队列&#xff1a;一种只允许一端进行插入数据操作&#xff0c;在另一端进行删除操作的特殊线性表。…...

WGS84地球坐标系,GCJ02火星坐标系,BD09百度坐标系简介与转换 资料收集

野火 ATGM332D简介 高性能、低功耗 GPS、北斗双模定位模块 STM32 GPS定位_为了维护世界和平_的博客-CSDN博客 秉火多功能调试助手上位机开源&#xff01;共六款软件&#xff0c;学到你吐... , - 电脑上位机 - 野火电子论坛 - Powered by Discuz! https://www.firebbs.cn/for…...

【面试题】前端面试复习6---性能优化

前端面试题库 &#xff08;面试必备&#xff09; 推荐&#xff1a;★★★★★ 地址&#xff1a;前端面试题库 性能优化 一、性能指标 要在 Chrome 中查看性能指标&#xff0c;可以按照以下步骤操作&#xff1a; 打开 Chrome 浏览器&#xff0c;并访问你想要测试…...

隧道HTTP具备的条件

作为一名专业的爬虫代理供应商&#xff0c;我们都知道使用代理是保证爬虫的高效性和稳定性的重要手段之一。而隧道代理则是近年来备受推崇的一种代理形式&#xff0c;它通过将请求通过隧道传输&#xff0c;可以有效地隐藏爬虫的真实IP地址&#xff0c;提高爬虫的反爬能力。 在…...

部署FTP服务(二)

目录 2.访问FTP服务 1.使用ftp命令行工具 2.使用浏览器 3.使用FileZilla Client 3.Serv-U 1.定义新域 2.创建用户 4. windowsserver搭建ftp服务器 一、FTP工具 二、Windows资源管理器 三、IE浏览器访问 2.访问FTP服务 下面在一台装有Windows10操作系统的计算机中&#…...

缓存的变更(JVM本地缓存->Redis分布式缓存)

在一次需求修改中&#xff0c;下游的服务附加提出了&#xff0c;针对某个业务数据缓存的生效时间的要求 原JVM设计方案&#xff1a; 采用jvm本地缓存机制&#xff0c;定时任务30秒刷新一次 现在redis方案&#xff1a; 因为很多地方使用了这个业务数据缓存&#xff0c;使用方…...

springMVC Unix 文件参数变更漏洞修复

错误信息如下&#xff1a; 解决方案&#xff1a; 原因&#xff1a;未对用户输入正确执行危险字符清理 未检查用户输入中是否包含“…”&#xff08;两个点&#xff09;字符串&#xff0c;比如 url 为 /login?action…/webapps/RTJEKSWTN26635&typerandomCode cookie为Coo…...

【LeetCode】494.目标和

题目 给你一个非负整数数组 nums 和一个整数 target 。 向数组中的每个整数前添加 或 - &#xff0c;然后串联起所有整数&#xff0c;可以构造一个 表达式 &#xff1a; 例如&#xff0c;nums [2, 1] &#xff0c;可以在 2 之前添加 &#xff0c;在 1 之前添加 - &#x…...

KaiwuDB 荣获哈佛商业评论 2023“高能韧性团队奖”

8月18日&#xff0c;《哈佛商业评论》中文版携手 FESCO 成功举办“第九届人才经济论坛”暨“2022-2023 高能团队奖颁奖典礼”。论坛秉承前沿的全球视野及权威的管理理念&#xff0c;发掘并展示本土企业组织管理的最佳实践&#xff0c;并重磅揭晓第二届“高能团队奖”评选结果。…...

删除ubuntu开始菜单中的图标

背景 本来是很好看干净的界面 更新谷歌浏览器后出现了Gmail&#xff0c;幻灯片&#xff0c;谷歌硬盘等跟谷歌相关的乱七八糟东西搞得界面就很丑 解决问题 删掉那个图标 输入命令 sudo nautilus /usr/share/applicationssudo nautilus ~/.local/share/applications可以…...

信息系统项目管理基础知识学习笔记 - IT 治理基础 - IT治理的驱动因素

信息系统项目管理基础知识学习笔记 - IT 治理基础 - IT治理的驱动因素 IT治理的驱动因素组织的IT战略驱动组织开展高质量IT治理因素IT治理的内涵IT 治理体系信息系统项目管理基础知识学习笔记 - IT 治理基础 - IT治理的驱动因素 IT治理的驱动因素 组织信息系统建设和运行需要…...

8月21-22日上课内容 第一章 MySQL数据库初始

本章结构 数据库的基本概念 概述&#xff08;总览&#xff09; 结构&#xff1a; 数据 表 数据库 数据库管理系统 数据库系统原理 数据 (Data) 描述事物的符号记录 包括数字&#xff0c;文字、图形、图像、声音、档案记录等以“记录”形式按统一的格式进行存储表 将不同…...

等级查询发布助手

考试成绩的发布是学校教学工作中的一项重要任务&#xff0c;传统的手工录入、统计和发布成绩的方式既耗时又容易出错。为了提高老师的工作效率和准确性&#xff0c;推荐老师们试一试易查分考试等级发布系统。 易查分是一个查询/发布发布平台 1. 快速高效&#xff1a;老师只需将…...

手搭手入门MyBatis-Plus

MyBatis-Plus Mybatis-Plus介绍 为简化开发而生 MyBatis-Plus(opens new window)&#xff08;简称 MP&#xff09;是一个 MyBatis(opens new window) 的增强工具&#xff0c;在 MyBatis 的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生。 特性 无侵入&#…...

AI 绘画Stable Diffusion 研究(十一)sd图生图功能详解-美女换装

免责声明: 本案例所用安装包免费提供&#xff0c;无任何盈利目的。 大家好&#xff0c;我是风雨无阻。 为了让大家更直观的了解图生图功能&#xff0c;明白图生图功能到底是干嘛的&#xff0c;能做什么事情&#xff1f;今天我们继续介绍图生图的实用案例-美女换装的制作。 对于…...

Servlet+JDBC实战开发书店项目讲解第14讲:订单管理功能

ServletJDBC实战开发书店项目讲解第14讲&#xff1a;订单管理功能 欢迎阅读本系列教程的第14讲&#xff01;在本篇文章中&#xff0c;我们将深入讲解如何在书店项目中实现订单管理功能。通过这个实例&#xff0c;你将学习到如何使用Servlet和JDBC来处理后台管理的订单管理操作…...

基于Linux操作系统中的shell脚本

目录 前言 一、概述 1、什么是shell&#xff1f; 2、shell脚本的用途有哪些&#xff1f; 3、常见的shell有哪些&#xff1f; 4、学习shell应该从哪几个方面入手&#xff1f; 4.1、表达式 1&#xff09;变量 2&#xff09;运算符 4.2、语句 1&#xff09;条件语句&am…...

8.22笔记

8.22笔记 8.22笔记一、Hive的HQL语法重点问题1.1 DDL1.1.1 Hive中数据表的分类问题1.1.2 特殊的数据类型 1.2 DML1.3 DQL1.3.1 查询语法和MySQL大部分都是一致的 1.4 讲了三个数据库的可视化工具1.4.1 navicat1.4.2 dbeaver1.4.3 chat2db 二、Hive中重点问题&#xff1a;Hive函…...

【以太网通信】RS232 串口转以太网

最近和 RK 研发同事在调试通信接口&#xff0c;排查与定位 RK3399 接收数据出错的问题。FPGA 与 RK3399 之间使用一路 RS232 串口进行通信&#xff0c;由于串口数据没有分包&#xff0c;不方便排查问题&#xff0c;想到可以开发一个 RS232 串口转以太网的工具&#xff0c;将串口…...

分享两道Java面试的算法上机题目(后续会持续补充更多)

所有题目参考答案均是小编自己想法&#xff0c;仅供参考&#xff0c;解法很多&#xff0c;大可不必局限&#xff0c;有更优解的大神无解&#xff0c;可评论或私聊博主指正&#xff01; 题目1 找大串&#xff0c;给定一个字符串其中包含任意组连续字符&#xff0c;我们把超过3个…...

如何使用CSS实现一个平滑过渡效果?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 使用CSS实现平滑过渡效果⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅 欢迎来到前端入门之旅&#xff01;这个专栏是为那些对Web开发感兴趣、刚…...

网络常见设备

目录 1.网络常见设备 1.交换路由设备 2.网络安全设备 3.无线网络设备 4.网络设备生产厂商 1.网络常见设备 当用户通过电子邮件给远方的朋友送去祝福时&#xff0c;一定不会想到这封邮件在网络中将会经历怎样复杂的行程。就好比将一封真实的信件投到邮局后&#xff0c;无法了解…...

数据结构与算法:通往编程高地的必修课(文末送书)

&#x1f935;‍♂️ 个人主页&#xff1a;艾派森的个人主页 ✍&#x1f3fb;作者简介&#xff1a;Python学习者 &#x1f40b; 希望大家多多支持&#xff0c;我们一起进步&#xff01;&#x1f604; 如果文章对你有帮助的话&#xff0c; 欢迎评论 &#x1f4ac;点赞&#x1f4…...

python小脚本——批量将PDF文件转换成图片

语言&#xff1a;python 3 用法&#xff1a;选择PDF文件所在的目录&#xff0c;点击 确定 后&#xff0c;自动将该目录下的所有PDF转换成单个图片&#xff0c;图片名称为: pdf文件名.page_序号.jpg 如运行中报错&#xff0c;需要自行根据报错内容按照缺失的库 例如&#x…...

cUrl的介绍和基本使用

cURL 如果你在开发接口的时候&#xff0c;需要调试。那么cUrl将是你必备的技能。也许你用过postman,但这个未免太重量级了。curl将会是你最佳轻量级&#xff0c;调试接口的工具&#x1f600; 1.Curl函数的基本选项✨ 1.1 --request和 -x —request 和 -X 指定与HTTP服务器通信…...

ONLYOFFICE协作空间服务器如何一键安装自托管私有化部署

ONLYOFFICE协作空间服务器如何一键安装自托管私有化部署 如何在 Ubuntu 上部署 ONLYOFFICE 协作空间社区版&#xff1f;https://blog.csdn.net/m0_68274698/article/details/132069372?ops_request_misc&request_id&biz_id102&utm_termonlyoffice%20%E5%8D%8F%E4…...

java分析公司名称:AI智能工具助力提取地名、品牌名、行业名

java分析公司名称&#xff1a;AI智能工具助力提取地名、品牌名、行业名 一、java智能提取地名 /*** 通过“武汉”补全省市区* throws Exception*/public void getPlace4() throws Exception{String r1 "武汉";String fileName2 "D:\\Personal\\Desktop\\txt…...

php 二维数组排序

要对二维数组进行排序&#xff0c;可以使用 PHP 的函数 array_multisort()。该函数可以按照指定的键值对对数组进行排序。 下面是一个示例代码&#xff0c;展示如何对二维数组按照某个键进行排序&#xff1a; // 定义一个二维数组 $students array(array(name > John, ag…...

postgresql 性能调优

性能调优是为了提高 PostgreSQL 数据库的性能和响应速度。下面是一些常见的 PostgreSQL 性能调优技巧&#xff1a; 1 确保合适的硬件资源&#xff1a;确保数据库服务器具有足够的内存、处理器和磁盘空间&#xff0c;以满足数据库负载的需求。2 优化查询语句&#xff1a;检查并优…...

派森 #P128. csv存json格式

描述 编写一个 Python 程序&#xff0c;读取movie.in&#xff08;csv格式&#xff0c;utf-8编码&#xff09; 的数据&#xff0c;将数据转成保存到movie.out(接送格式&#xff0c;utf-8编码)文件中。 格式 输入 movie.in文件&#xff0c;测试格式&#xff0c;utf-8编码。 …...

iPhone开启“轻点唤醒”功能但点击屏幕无反应怎么解决?

iPhone的“轻点唤醒”功能启用时&#xff0c;用户只需手指轻触或点击手机屏幕即可快速唤醒设备&#xff0c;无需按压任何按钮。然而&#xff0c;有些用户在使用“轻点唤醒”功能唤醒屏幕时&#xff0c;遇到该功能失灵&#xff0c;无法正常唤醒屏幕的情况&#xff0c;这是怎么回…...

论AI与大数据之间的关系

前言 在21世纪&#xff0c;"AI"和"大数据"已经成为科技领域的热门词汇。它们不仅是创新的代名词&#xff0c;更是现代技术发展的双翼。然而&#xff0c;很多人对于AI与大数据之间的关系仍然停留在表面的理解。本文旨在深入探讨这两者之间的深厚关系&#…...

6.ES基础概念及术语详细解读

一、Elasticsearch概述&#xff1a; ES是基于Lucene的搜索服务器&#xff0c;它提供了一个分布式多用户能力的全问搜索引擎&#xff0c;且ES支持RestFulweb风格的url访问。ES是基于Java开发的开源搜索引擎&#xff0c;设计用于云计算&#xff0c;能够达到实时搜索&#xff0c;…...

大语言模型微调实践——LoRA 微调细节

1. 引言 近年来人工智能领域不断进步&#xff0c;大语言模型的崛起引领了自然语言处理的革命。这些参数量巨大的预训练模型&#xff0c;凭借其在大规模数据上学习到的丰富语言表示&#xff0c;为我们带来了前所未有的文本理解和生成能力。然而&#xff0c;要使这些通用模型在特…...

国内ChatGPT对比与最佳方案

很久没写内容了&#xff0c;主要还是工作占据了太多时间。简单分享下我这段时间的研究吧,由于时间仓促&#xff0c;有很多内容没有具体写&#xff0c;请自行到我分享的网站体验查看。 前言 ChatGPT 的出现确实在很大程度上改变了世界。许多人已经亲身体验到了ChatGPT作为一个…...

绝美的古诗词AI作画,惊艳到我了!

前言 时光荏苒&#xff0c;科技的飞速发展催生出了许多令人惊叹的创新成果。近年来&#xff0c;人工智能技术在艺术领域的应用日益引人注目&#xff0c;其中最为引人瞩目的莫过于AI作画。这项技术将传统的古诗词与现代的人工智能相结合&#xff0c;创造出一幅幅令人叹为观止的…...

数据结构—排序

8.排序 8.1排序的概念 什么是排序&#xff1f; 排序&#xff1a;将一组杂乱无章的数据按一定规律顺序排列起来。即&#xff0c;将无序序列排成一个有序序列&#xff08;由小到大或由大到小&#xff09;的运算。 如果参加排序的数据结点包含多个数据域&#xff0c;那么排序往…...

GraphScope,开源图数据分析引擎的领航者

文章首发地址 GraphScope是一个开源的大规模图数据分析引擎&#xff0c;由Aliyun、阿里巴巴集团和华为公司共同开发。GraphScope旨在为大规模图数据处理和分析提供高性能、高效率的解决方案。 Github地址&#xff1a; https://github.com/alibaba/GraphScope GraphScope 的重…...

【Linux】邮件服务器搭建 postfix+dovecot+mysql (终极版 超详细 亲测多遍无问题)

&#x1f341;博主简介 &#x1f3c5;云计算领域优质创作者   &#x1f3c5;华为云开发者社区专家博主   &#x1f3c5;阿里云开发者社区专家博主 &#x1f48a;交流社区&#xff1a;运维交流社区 欢迎大家的加入&#xff01; 文章目录 前言基础原理准备工作一 、安装关于权…...

GitLab与GitLab Runner安装(RPM与Docker方式),CI/CD初体验

背景 GitLab 是一个强大的版本控制系统和协作平台&#xff0c;记录一下在实际工作中关于 GitLab 的安装使用记录。 一开始使用 GitLab 时&#xff0c;是在 CentOS7 上直接以 rpm 包的方式进行安装&#xff0c;仅作为代码托管工具来使用&#xff0c;版本&#xff1a; 14.10.4 …...

vue3+element下拉多选框组件

<!-- 下拉多选 --> <template><div class"select-checked"><el-select v-model"selected" :class"{ all: optionsAll, hidden: selectedOptions.data.length < 2 }" multipleplaceholder"请选择" :popper-app…...

Python科研绘图--Task02

目录 图形元素 画布 (fifigure)。 坐标图形 (axes)&#xff0c;也称为子图。 轴 (axis) &#xff1a;数据轴对象&#xff0c;即坐标轴线。 刻度 (tick)&#xff0c;即刻度对象。 图层顺序 轴比例和刻度 轴比例 刻度位置和刻度格式 坐标系 直角坐标系 极坐标系 地理…...