Mybatis-Plus实现分页查询

Mybatis-Plus实现分页查询

先配置一个PageConfig分页配置类,注意加上配置注解:

@Configuration
public class PageConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }


}

随后可以按如下代码进行调用,非常方便:

Page<User> page=new Page<>(2,10);
userMapper.selectPage(page,null);
System.out.println(page.getRecords());

 

posted @ 2021-07-09 11:51  onecyl  阅读(5144)  评论(0编辑  收藏  举报