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

引入jar包

之前引入的是

<dependency>
    <groupId>com.github.pagehelpergroupId>
    <artifactId>pagehelperartifactId>
    <version>5.1.8version>
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.pagehelpergroupId>
    <artifactId>pagehelper-spring-boot-starterartifactId>
    <version>1.2.10version>
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;
		}
	}

查询结果

SpringBoot集成Mybatis分页插件PageHelper不生效问题_第1张图片

你可能感兴趣的:(Spring,Boot)