1.在pom文件中添加依赖

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- mybatis-plus启动器 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
        </dependency>

2.在application.yml文件中添加数据库连接配置

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/jiaoyoushe?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: 123456

3.创建entity包并在其中创建对应数据库表的实体类class

@Data
@Data
@TableName("user")//指定表名字
public class User {

    //主键
    @TableId(type = IdType.AUTO)//@TableId代表主键 不设置type则用雪花算法自动生成
    private Long id;

    //姓名
    @TableField(value = "nickname",condition = SqlCondition.LIKE )
    private String nickname;

    //创建时间
    private LocalDateTime gmtCreate;

    //修改时间
    private LocalDateTime gmtModified;

    //备注
//    private transient String remark;//transient非数据库字段 不参与序列号

//    private static String remark;//static非数据库字段 参与序列号

    @TableField(exist = false)//代表数据库不存在的字段
    private String remark;
}

备注:@Data为lombok注解
4.创建dao包并在其中创建mapper接口interface继承extends BaseMapper<实例类名>

public interface UserMapper extends BaseMapper<User> {
}

5.在mapper接口上添加注解@Component("xxx")或者在启动类上添加注解扫描包

@MapperScan("xxx.xxx.xxx.dao")

Q.E.D.

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

You got to put the past behind you before you can move on.