SpringBoot集成Mybatis分页插件PageHelper不生效问题

引入jar包

之前引入的是

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.8</version>
</dependency>

只有这一个包
在这里插入图片描述
在这种情况下需要在项目的入口类application.java加入额外配置

// 解决springboot 与pageHelper分页查询问题
	@Bean
	public PageHelper pageHelper() {
		PageHelper pageHelper = new PageHelper();
		Properties properties = new Properties();
		properties.setProperty("offsetAsPageNum", "true");
		properties.setProperty("rowBoundsWithCount", "true");
		properties.setProperty("reasonable", "true");
		properties.setProperty("dialect", "mysql");
		pageHelper.setProperties(properties);
		return pageHelper;
	}

引入适配Spring Boot包

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

发现这里会多出两个包,不需要加任何配置
在这里插入图片描述

使用
	@ApiOperation(value = "列表查询", httpMethod = "GET", produces = "application/json")
	@RequestMapping(value = "/onSearch", method = RequestMethod.GET)
	public PageInfo<AlmRecord> getByParams(@ApiParam(value = "用于查询的条件") @RequestParam(required = false) Map<String, String> params) {
		try {
			logger.info("AlmRecordController getByParams id=" + params);
			PageHelper.startPage(Integer.parseInt(params.get("offset")), Integer.parseInt(params.get("limit")));
			 List<AlmRecord> selectById = service.selectByParams(params);
			 PageInfo<AlmRecord> appsPageInfo = new PageInfo<>(selectByParams);
			return selectById;
		} catch (Exception e) {
			logger.error("AlmRecordController getByParams error:", e);
			return null;
		}
	}
查询结果

在这里插入图片描述

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值