复习笔记10-SpringBoot  postman 统一响应结果 分层 MYSQL MyBatis

## 1.SpringBoot
#### ①创建工程
https://start.spring.io/
解压文件放到一个没有中文没有空格的路径下,用IDEA打开
😊响应码：
404：请求资源不存在，一般是url输入有误，或者网站资源被删除了
## 2.postman工具
常用于进行接口测试
#### 😊注解
1-RequestParam:方法形参名称与请求参数名称不匹配，通过该注解完成映射
2-RequestParam：集合形参前加此注解
3-DateTimeFormat:日期参数格式转换
## 3.统一响应结果(ResponseBody)
①code:响应码 比如0代表返回成功 1代表返回失败
②msg: 提示信息 比如 失败啦 成功啦
③date:返回的数据 比如 String List ...
😊统一响应结果：Result
## 4.分层
Controller:接收前端发送的请求，对请求进行处理，并响应数据
Service:处理具体的业务逻辑
Dao:数据访问操作，包括数据的增删改查
## 5.注解
1-RequestMapping：后面添加路径
2-RequestBody:json参数
3-PathVariable：获取路径参数
4-SpringBootApplication:具有包扫面作用，默认扫描当前包及其子包
## 6.数据库操作
查询所有数据库：show databases;
查询当前数据库：select databases();
使用数据库：use 数据库名;
创建数据库：create databases if not exists 数据库名;
删除数据库：drop databases if  exists 数据库名;
## 7.表结构操作
#### ①创建
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/a698eed1-edaa-9659-3b5a-7befcc4399ed.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/a852ec3a-5183-d2bb-0c56-efaf1efe2f9f.png)
#### ②查询
查询当前数据库所有表：show tables;
查询表结构：desc 表名；
查询建表语句：show create table 表名；
#### ③修改
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/7e8cc7d8-c34b-fa09-ad39-835db501e62e.png)
#### ④删除
删除表：drop table if exists 表名;
在删除表时，表中的全部数据也会被删除
## 8.数据操作
#### ①添加数据(insert)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/c2f56310-33e0-594f-cd8f-34f2661d8b49.png)
#### ②修改数据(update)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/e3691eb0-13c0-3c35-de80-fcf478d95386.png)
#### ③删除数据(delete)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/2f584a5e-a99f-b890-f591-898db3ed25c6.png)
## 9.查询
#### ①基本查询
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/a90b8c22-b1c9-4f5f-bf63-748c1ae5c109.png)
#### ②条件查询where
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/d46359b6-be62-bbf3-9db7-7a9ae0c79f04.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/8c1cb071-1cf8-d217-b1ef-4e6e643be6e6.png)
#### ③分组查询group by
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/ed56260b-d167-9c2a-5261-e7b72cc1f9e2.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/ef43a89d-3102-2ab1-d766-22238515bd5e.png)
#### ④排序查询order by
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/ed9bb831-6548-921c-08b9-f4d9e37f68dd.png)
升序（默认）：ASC
降序：DESC
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/c331853c-da26-9d91-f0d2-c2f337826e32.png)
#### ⑤分页查询limit
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/51545d72-7393-2a96-2ffe-1c729119b4b3.png)
起始索引= （页码-1）*每页展示的记录数
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/fee4f56b-56b0-d9ee-632e-bb8df9b98de4.png)
## 10.聚合函数
将一列数据作为一个整体，进行纵向计算
语法：select 聚合函数(字段列表) from 表名；
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/aa3345aa-ac2f-0c32-e4e9-b877fb777d58.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/46274ff1-be13-9e52-f594-852af5325313.png)
## 11.多表设计
一对多：在多的一方添加外键，关联另外一方的主键
一对一：任意一方，添加外键，关联另外一方的主键
多对多：通过中间表来维护，中间表的两个外键，分别关联另外两张表的主键
## 12.多表查询
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/603081b9-2215-3daf-894b-d5f0e81bc0a8.png)
#### ①内连接
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/82764b60-7156-be69-8466-0fe348695b08.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/fd9df761-f3f3-9c63-aae0-d941d624f430.png)
#### ②外连接
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/c7a91214-bc3e-2b18-6545-0e86987ea696.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/9bd6baad-69e2-6db2-c97e-f789e4bfe537.png)
## 13.事务
要么全部成功，要么全部失败
开始事务：start transaction; / begin;
提交事务：commit;
回滚事务：rollback;
## 14.索引
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/122fde1a-15d9-c052-abb9-4f1fadb8e0cc.png)
## 15.MyBatis（持久层框架）
把java和mysql连接起来
#### ①配置数据库连接信息
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/5c73a726-fe1f-ceaf-16ab-4548903eaab3.png)
#### ②Lombok
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/14b8cc5d-dd77-4fd3-dc6d-129f3d727b58.png)
#### ③修改properties文件编码
https://blog.csdn.net/startyangu/article/details/130621161
## 16.XML映射文件
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/a4c9fffd-3d94-237c-ef27-da9822bdda0e.png)
## 17.数据库建立连接
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/a46b219a-aea4-fb62-ac09-2587a20cd61b.png)
## 18.开发规范-Restful
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3899383/56f2410f-4394-6b7c-c51e-1cf1c6b3ea8b.png)