1.引入依赖包
<!--mybatisPlus包-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<!--数据库包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--lombok插件包-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
2.连接数据库
spring.datasource.username=root
spring.datasource.password=root
//mysql8版本以上需要配置内容
spring.datasource.url=jdbc:mysql://localhost:3306/day02-1?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
3.写pojo类以及mapper持久层
package com.xc.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class emp {
private Integer empno;
private String ename;
private String job;
private Integer mgr;
private Date hiredate;
private Integer sal;
private Integer comm;
private Integer deptno;
}
package com.xc.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xc.pojo.emp;
import org.springframework.stereotype.Repository;
@Repository //代表持久层
public interface empMapper extends BaseMapper<emp> {
}
//在这里继承BaseMapper这个类,BaseMapper<T> 这个T为泛型内容
//写入你需要传入的pojo对象即可
5.在springBoot测试内部进行测试,基本的CRUD都可以实现