MybatisPlus依赖

MybatisPlus依赖(核心)

在Springboot项目的pom文件中加入

1
2
3
4
5
6
<!--        mybaits-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3.1</version>
</dependency>

在Springboot项目的yaml文件中加入(参数可自行修改)

1
2
3
4
5
6
7
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
configuration:
#驼峰命名法映射
map-underscore-to-camel-case: true
#二级缓存
cache-enabled: false

swagger依赖(非必要)

在Springboot项目的pom文件中加入

1
2
3
4
5
6
7
8
9
10
11
<!--swagger-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>4.1.0</version>
</dependency>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

在Springboot项目的yaml文件中加入(参数可自行修改)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
knife4j:
enable: true
openapi:
title: 用户管理接口文档
description: "用户管理接口文档"
email: zhanghuyi@itcast.cn
concat: AE
url: https://www.itcast.cn
version: v1.0.0
group:
default:
group-name: default
api-rule: package
api-rule-resources:
- com.itheima.mp.controller

MybatisPlus常用注解

表注解

注解 描述
@TableName 用来指定表名
@TableId 用来指定表中的主键字段信息
@TableField 用来指定表中的普通字段信息

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@TableName("tb_user")
public class User {

/**
* 用户id
*/
@TableId(value = "tb_id",type = IdType.ASSIGN_ID)
private Long id;

/**
* 用户名
*/
@TableField("`tb_username`")
private String username;

@TableField(exist = false)
private String password;

}

User 里的均为成员变量
实际数据库表名为 tb_user
实际数据库主键为 tb_id
实际数据库普通字段名为 tb_username
exist = false 表示password字段 在真实数据库中是不存在的

`表转义(如果你的变量名为数据库语句的关键字)
ASSIGN_ID表示使用mybatisplus的雪花算法生成id
AUTO 自增
INPUT 通过set方法自行输入

持续更新中