目录
1.2、SpringBoot 引入 MyBatis-Plus 开发场景
1、MyBatis-Plus 配置
1.1、什么是MyBatis-Plus
MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
MyBatis Plus:中文官网
1.2、SpringBoot 引入 MyBatis-Plus 开发场景
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
场景自动导入依赖:
2、MyBatis-Plus 使用
需要操作的对象:对象的属性需要都在数据库中,如果没有则添加注解 @TableField(exist = false)
//利用lombok添加get、set方法
@Data
@AllArgsConstructor
@NoArgsConstructor
// MyBatis默认类名即为要操作的表名
// 当类名和表名不一致时,使用该注解标明表名
@TableName("User")
public class User {
//所有属性都应该在数据库中
@TableField(exist = false)
private String userName;
@TableField(exist = false)
private String passWord;
//以下是数据库字段
private Long id;
private String name;
private Intege