MyBatis分页插件的使用----->PageHelper

1.在Maven配置PageHelper插件

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.2.0</version>
</dependency>

2.在mybatis核心配置文件中配置PageHelper插件

  • params:为了支持startPage(Object params)方法,增加了该参数来配置参数映射,用于从对象中根据属性名取值, 可以配置 pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值, 默认值为pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero。
<!--
    plugins在配置文件中的位置必须符合要求,否则会报错,顺序如下:
    properties?, settings?,
    typeAliases?, typeHandlers?,
    objectFactory?,objectWrapperFactory?,
    plugins?,
    environments?, databaseIdProvider?, mappers?
-->
<plugins>
    <!-- com.github.pagehelper为PageHelper类所在包名 -->
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        <!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
        <property name="param1" value="value1"/>
	</plugin>
</plugins>

3.使用

 //设置分页参数
 
    //PageHelper.startPage(1,2);,当前页数,每页数据数量
    //在数据库连接的service类中
    public PageInfo<Student> part(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        //正常查询,则会根据上面,进行注入,按页查询
        List<Student> all = dao.all();
        //返回的是 PageInfo<Student>,是student类
        PageInfo<Student> pageInfo = new PageInfo(all);
        return pageInfo;
    }

 //使用PageHelper进行查询分页数据
        PageHelper.startPage(currentPage, pageSize);
        PageInfo<Student> part = server.part(currentPage, pageSize);

						// let data = rz.data.list;
                        //将数据赋值给 tableData
                         //tb.tableData = data;
                          //tb.pagination.total= rz.data.total;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值