com.baomidou

mybatis-plus-boot-starter 3.5.1 1 2 3 4 5 4.配置编码 配置 application.yml 文件 在 Spring Boot 启动类中添加 @MapperScan 注解,扫描 Mapper 文件夹 #配置端口 server: port: 80 spring: #配置数据源 datasource: #配置数据源类型 type: com.zaxxer.hikari.HikariDataSource #配置连接数据库的信息 driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf8&useSSL=false username: {username} password: {password} #MyBatis-Plus相关配置 mybatis-plus: configuration: #配置日志 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 编写实体类 User.java (此处使用了 Lombok 简化代码) 编写 Mapper 包下的 UserMapper 接口 5.测试查询 编写一个测试类 MyBatisPlusTest.java 控制台打印查询结果 @SpringBootApplication @MapperScan("指定Mapper接口所在的包") public class MybatisPlusDemoApplication { public static void main(String[] args) { SpringApplication.run(MybatisPlusDemoApplication.class, args); } } 1 2 3 4 5 6 7 @Data public class User { private Long id; private String name; private Integer age; private String email; } 1 2 3 4 5 6 7 1 public interface UserMapper extends BaseMapper 说明: 通用 CRUD 封装BaseMapper 接口,为