1.在配置类中添加分页插件
- @Configuration
- @EnableTransactionManagement
- @MapperScan("xxx.xxx.xxx.xxx")
- public class MybatisPlusConfig {
- /**
- * 分页插件
- */
- @Bean
- public PaginationInterceptor getPaginationInterceptor(){
- return new PaginationInterceptor();
- }
-
- }
2.创建测试类进行方法的调用
- @SpringBootTest
- public class MybatisPlusTest {
-
- @Autowired
- private UserMapper userMapper;
-
- @Test
- public void selectByPage(){
- Page
userPage = new Page<>(2,3); - userMapper.selectPage(userPage,null);
- List
records = userPage.getRecords(); - records.forEach(System.out::println);
- System.out.println(userPage.getCurrent());
- System.out.println(userPage.getPages());
- System.out.println(userPage.getSize());
- System.out.println(userPage.getTotal());
- System.out.println(userPage.hasNext());
- System.out.println(userPage.hasPrevious());
- }
- }