项目：08-SpringBoot3集成Mybatis

## 一：SpringBoot配置Mybatis
⭐application.yml
设置 MyBatis 的映射文件路径、日志输出方式以及如何处理数据库字段和 Java 实体属性之间的命名规则。
```java
# 配置mybatis实体和xml映射
mybatis:
  # 映射XML
  mapper-locations: classpath:mapper/*.xml
  configuration:
    # 配置日志
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/2e8a1b26-8486-f3cd-d012-d8c3d28832ff.png)
⭐java表示属性一般使用驼峰的形式：deptId
数据库里面表示字段一般使用下划线的形式：dept_id
## 二：基本的xml格式
```java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.EmployeeMapper">
</mapper>
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/d585e477-2878-9c77-a5f3-b4dbf3d6ede0.png)
#### 1.xml是跟mapper接口一一对应的
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/5027a3c2-2d69-eb53-1ea7-efbc30260468.png)
#### 2.告诉springboot如何扫描mapper包
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/84d2569f-2c6e-a917-4ca8-80f98cafc4d3.png)
#### 3.查询员工表所有信息
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/410a8100-7808-58b8-b9d2-1ac2b40d3b1a.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/debf24cb-6df2-8362-51b7-4a711849cb93.png)
#### 4.根据id查询员工信息
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/e2ad6b59-8f1c-5806-0e32-3501c315d884.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/04b44eba-9603-9dfd-a748-5ce7c39b9539.png)
#### 5.分页查询
⭐①引入分页查询插件
```java
<!-- 分页插件PageHelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.4.6</version>
    <exclusions>
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </exclusion>
    </exclusions>
</dependency>
```
⭐②代码
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/919e7d42-d998-3ac9-11ce-4ccad4f4f6e5.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/fa4e40e2-aba3-f8dd-5a83-c8e9a268b6a8.png)

#### 6.接口传参方式
⭐①RequestParam注解：
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/103459b5-abf5-363d-0f8b-a3837ac6341a.png)
⭐②PathVariable注解：
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/efb004c9-d49e-7aea-eff4-dc79900de62d.png)
⭐③对象参数：通过对象可以接受多个url参数
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/6886a0a8-48d7-aaf3-e82e-f8f63b585651.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/5fde64af-39b6-3e05-5187-4d62664ea71f.png)
## 三：使用Mybatis实现数据库的增删改查
#### 1.get:查询操作
#### 2.post:新增操作
通过RequestBody注解，可以把前端传来的json字符串映射成java的对象或者数组
⭐Mybatis里面写sql使用下划线，涉及到绑定java对象值就写驼峰
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/f3d6d9a4-1a2b-8392-221f-aebd0c526cca.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/eb5f9b58-4eae-dc46-195e-440725236fce.png)
#### 3.put:修改操作
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/f65b1496-86e5-bece-e4b4-aad233ceee87.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/9704c8e9-0751-dfa4-8d2e-bb839adc08e6.png)
#### 4.delete:删除操作
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/ee75d968-7bbf-6226-2397-40ecf2c52524.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/c0674323-e4ce-ffc4-e7e8-d1e38f10fca0.png)