在整合mybatis-plus时可以先参考官网:快速开始
一、引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
二、yml文件配置
spring.datasource.url=jdbc:mysql://localhost/chapter01?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
?三、创建实体类
@Data
public class SysUser {
private int id;
private String username;
private String password;
}
四、分页插件配置
@Configuration
public class MyBatisConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
五、应用实例
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
Page<SysUser> page = new Page();
page.setCurrent(2);
page.setSize(10);
Page<SysUser> page1 = sysUserMapper.selectPage(page, queryWrapper);
List<SysUser> records = page1.getRecords();
System.out.println(records);
详细代码请看:springboot整合mybatis-plus分页
|