mybatisPlus分页查总数
Page类在mybatisPlus中用于分页查询,继承Pagination类,Pagination类的searchCount字段控制是否查询总记录数
顺着看哪里用到了searchCount:
com.baomidou.mybatisplus.plugins.PaginationInterceptor 是mybatisPlus的一个插件,也就是说mybatis是通过插件的方式在分页的时候查询总数;
红圈中使用sql解析包jsqlparser根据原sql生成count语句,查询出总数然后set到page中,这里有两个前提条件
- rowBounds是Pagination类型对象;
- searchCount=true;
rowBounds怎么来的?
可以看到rowBounds是statementHandler对象的一个属性;
org.apache.ibatis.binding.MapperMethod
来到这里基本看明白了,mybatisPlus会从Mapper的方法的参数筛选出RowBounds类型的对象,然后
设置到statementHandler中,才有了上面我们说到的从statmentHandler取出rowBounds对象;文章来源:https://www.toymoban.com/news/detail-638919.html
org.apache.ibatis.executor.SimpleExecutor#doQuery
如何实现XML自定义sql分页同时查总数?
我们需要在自定义的Mapper方法中,添加一个Page类型参数即可,参考com.baomidou.mybatisplus.service.impl.ServiceImpl#selectPage(com.baomidou.mybatisplus.plugins.Page, com.baomidou.mybatisplus.mapper.Wrapper)文章来源地址https://www.toymoban.com/news/detail-638919.html
到了这里,关于窥探系列之Mybatis-plus XML分页查询的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!