Pagehelper插件

一、引入依赖

<!-- pageHelper 插件 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper-spring-boot-starter</artifactId>
				<version>${pagehelper.version}</version>
			</dependency>

二、配置yml

# PageHelper 分页插件配置
pagehelper:
  helper-dialect: oracle
  reasonable: true
  support-methods-arguments: true
  params: count=countsql
#设置后如果 pageSize=0 就会查询出全部的结果(相当于没有执行分页查询)
  page-size-zero: true
  1. helper-dialect:指定数据库,不指定的话会默认自动检测数据库类型
  2. reasonable:是否启动分页合理化。如果启用,当 pagenum < 1 时,会自动查询第一页的数据,当 pagenum > pges 时,自动查询最后一页数据;不启用的,以上两种情况都会返回空数据,如果启用则 pageHelper可以自动拦截请求参数中的 pageNum,pageSize参数,否则需要使用 PageHelper.startPage(pageNum,pageSize) 方法调用。
  3. support-methods-arguments:默认为 false,分页插件会从查询方法的参数值中,自动根据上面 params 配置的字段中取值,查找到合适的值时就会自动分页。
  4. params:用于从对象中根据属性名取值,可以配置 pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值,默认值为 pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero

三、使用

package com.atieslab.czxt.cz.service.impl;

import com.atieslab.czxt.cz.common.util.JedisUtils;
import com.atieslab.czxt.cz.mapper.CzxxMapper;
import com.atieslab.czxt.cz.model.vo.CzxxQueryInfoVo;
import com.atieslab.czxt.cz.service.CzxxService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @ClassName: CzxxServiceImpl
 * @DescriptionL CzxxService实现类
 * @author: xzt
 * @date: 2023年07月21日14:02
 * @Version: 1.0
 */
@Service
@Slf4j
public class CzxxServiceImpl implements CzxxService {
    @Autowired
    CzxxMapper czxxMapper;

    @Autowired
    JedisUtils jedisUtils;

    @Override
    public List<CzxxQueryInfoVo> getAllInfoList(Integer page, Integer limit) {
        // 设置第几条记录开始,多少页记录为一页
        PageHelper.startPage(page,limit);
        List<CzxxQueryInfoVo> allInfoList = czxxMapper.getAllInfoList();
        Jedis jedis = jedisUtils.getJedis();
        String name = jedis.get("name");
        log.info("redis得到的数据:{}",name);
        jedisUtils.close(jedis);
        return allInfoList;
    }
}

还可使用PageInfo类来进行详细信息打印

        PageInfo<CzxxQueryInfoVo> info = new PageInfo<>(czxxQueryInfoVoList);
        log.info("分页信息:{}",info.toString());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值