0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2025-01-09

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
image.png

②查询

查询当前数据库所有表:show tables;
查询表结构:desc 表名;
查询建表语句:show create table 表名;

③修改

image.png

④删除

删除表:drop table if exists 表名;
在删除表时,表中的全部数据也会被删除

8.数据操作

①添加数据(insert)

image.png

②修改数据(update)

image.png

③删除数据(delete)

image.png

9.查询

①基本查询

image.png

②条件查询where

image.png
image.png

③分组查询group by

image.png
image.png

④排序查询order by

image.png
升序(默认):ASC
降序:DESC
image.png

⑤分页查询limit

image.png
起始索引= (页码-1)*每页展示的记录数
image.png

10.聚合函数

将一列数据作为一个整体,进行纵向计算
语法:select 聚合函数(字段列表) from 表名;
image.png
image.png

11.多表设计

一对多:在多的一方添加外键,关联另外一方的主键
一对一:任意一方,添加外键,关联另外一方的主键
多对多:通过中间表来维护,中间表的两个外键,分别关联另外两张表的主键

12.多表查询

image.png

①内连接

image.png
image.png

②外连接

image.png
image.png

13.事务

要么全部成功,要么全部失败
开始事务:start transaction; / begin;
提交事务:commit;
回滚事务:rollback;

14.索引

image.png

15.MyBatis(持久层框架)

把java和mysql连接起来

①配置数据库连接信息

image.png

②Lombok

image.png

③修改properties文件编码

16.XML映射文件

image.png

17.数据库建立连接

image.png

18.开发规范-Restful

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?