springboot 0-1之pagehelper分页

1、pom.xml安装依赖

<dependency>
     <groupId>com.github.pagehelper</groupId>
     <artifactId>pagehelper-spring-boot-starter</artifactId>
     <version>1.2.10</version>
 </dependency>

2、配置
application.yml

pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true

resource/mybatis-config.xml

<plugins>
    <plugin interceptor="com.github.pagehelper.PageInterceptor">
        <property name="helperDialect" value="mysql"/>
    </plugin>
</plugins>

3、启动类

@SpringBootApplication(exclude = PageHelperAutoConfiguration.class)

排除自动化配置,否则运行时会提示:在系统中发现了多个分页插件,请检查系统配置!
4、使用
controller

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

@PostMapping("/findListByPage")
 public BaseResponse findListByPage(@Validated @RequestBody BasePage req, BindingResult results){
     Page listParam = new Page(req.getPageNum(), req.getPageSize());
     PageInfo<User> pageInfo = userService.findListByPage(listParam);
     return BaseResponse.success(pageInfo);
 }

获取分页数据

@Override
public PageInfo<User> findListByPage(Page listParam) {
	// 两种方法
	// 方法一:
	// 注意引入顺序,startPage调用完之后需要立即调用sql,否则会导致分页无法结束,下次调用sql拼接limit
    // 设置分页参数
    PageHelper.startPage(listParam.getPageNum(),listParam.getPageSize(), true);
    // 进行分页查询
    List<User> userList = userMapper.findListByPage();
    // 获取分页信息
    PageInfo<User> pageInfo = new PageInfo<>(userList);
    return pageInfo;
    
    // 方法二:
    return PageHelper.startPage(listParam.getPageNum(), listParam.getPageSize()).doSelectPageInfo(() -> userDao.findListByPage());
}

出现问题:
User实体继承了Page类,导致反序列化一直失败,警醒!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值