Python 官方文档:入门教程 => 点击学习
目录1.写个mybatis-plus配置类:2.写接口测试3.注意4.如果你还有查询条件1.Lambda表达式2.普通查询总结1.写个Mybatis-plus配置类: 是通过拦截器实
是通过拦截器实现分页
@Configuration
public class MybatisConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.Mysql));
return interceptor;
}
}
官网复制即可,只是你需要把数据库改为你使用的,这里我是使用mysql
很简单
@GetMapping("/test")
public Response test(){
Page<Produce> producePage = new Page<>(1,1);
Page<Produce> page = produceService.page(producePage);
System.out.println(producePage == page);
List<Produce> records = page.getRecords();
for (Produce record : records) {
System.out.println(record);
}
return new Response<>(records, ResultEnum.SUCCESS);
}
默认是会查询总条数,都有get、set方法,可以根据自己的需求设置(点开Page类看看)
我们传入的page对象和查询返回的page对象是同一个
比如我们只查询id和price,id小于5的分页查询
@GetMapping("/test")
public Response test(){
Page<Produce> producePage = new Page<>(1,2);
Page<Produce> page = new LambdaQueryChainWrapper<>(produceService.getBaseMapper())
.select(Produce::getPid,Produce::getPrice)
.lt(Produce::getPid,5)
.page(producePage);
return new Response<>(page.getRecords(), ResultEnum.SUCCESS);
}
@GetMapping("/test")
public Response test(){
Page<Produce> producePage = new Page<>(1,2);
QueryWrapper<Produce> queryWrapper = new QueryWrapper<>();
queryWrapper.select("pid","price");
queryWrapper.lt("pid",5);
Page<Produce> page = produceService.page(producePage, queryWrapper);
return new Response<>(page.getRecords(), ResultEnum.SUCCESS);
}
到此这篇关于Mybatis-Plus分页的使用与注意事项的文章就介绍到这了,更多相关Mybatis-Plus分页使用内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Mybatis-Plus分页的使用与注意事项
本文链接: https://www.lsjlt.com/news/146966.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0