mysql分页插件springboot_SpringBoot集成MyBatis的分页插件PageHelper--详细步骤

1.pom中添加依赖包

com.github.pagehelper

pagehelper

5.1.2

com.github.pagehelper

pagehelper-spring-boot-autoconfigure

1.2.5

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.5

2.配置分页插件

下面二者选一配置

2.1.application.properties配置

在application.properties文件中添加如下配置

#分页插件

pagehelper.helper-dialect=MYSQL

pagehelper.reasonable=true

pagehelper.support-methods-arguments=true

pagehelper.params=count=countSql

2.2.配文件配置对象

package com.qiaXXXXXX.config;

import com.github.pagehelper.PageHelper;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**

* @Copyright (C) 四川XXXX

* @Author: LI

* @Date: 7/1 11:01

* @Description:

*/

@Configuration

public class PageHelperConfig {

@Bean

public PageHelper getPageHelper() {

PageHelper pageHelper = new PageHelper();

Properties properties = new Properties();

properties.setProperty("helperDialect", "mysql");

properties.setProperty("reasonable", "true");

properties.setProperty("supportMethodsArguments", "true");

properties.setProperty("params", "count=countSql");

pageHelper.setProperties(properties);

return pageHelper;

}

}

3.分页实现

@Override

public PageInfo getMyOrder(MyOrderObj obj) {

if (StringUtils.isEmpty(obj.getQueryMonth())) {

String endMonth = DateUtil.getEndMonth();

obj.setStartMonth(DateUtil.getStartMonth(endMonth));

obj.setEndMonth(endMonth);

} else {

obj.setStartMonth(null);

obj.setEndMonth(null);

}

//设置分页参数

PageHelper.startPage(obj.getPageNo(), obj.getPageSize());

//查询列表数据

List list = userCenterMapper.getMyOrder(obj);

//获取分页对象

PageInfo pageInfo = new PageInfo<>(list);

return pageInfo;

}

注意:有了分页插件,sql语句不需要写limit,插件会在执行的sql中自动添加,也不需要自己单独写count语句获取总共条数,分页插件会自动获取.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值