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());