1.去官网复制分页内容
2.拷贝到配置类中
//配置类
@Configuration
@MapperScan("com.bot.demo.mapper")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}
3.就可以使用了
Page<Product> page=new Page<>(pageNum,pageSize);
//查询条件
QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("discribe","123");
//使用service查询
page= productService.page(page,queryWrapper);
//使用mapper查询
//mapper .selectPahe(page,) 后面是查询条件,没有则为null
return page;
MyBatis Plus 分页查询实战
本文介绍如何在 MyBatis Plus 中实现分页查询功能。首先从官网获取配置代码,接着将其添加到项目的配置类中启用分页拦截器。最后通过 Service 或 Mapper 层进行分页查询操作。
348

被折叠的 条评论
为什么被折叠?



