设置size为5,但是最后还是查询出来的条数
PageHelper.startPage(page,size);//size为5
//2条件查询
ProductInfoExample productInfoExample = new ProductInfoExample();
ProductInfoExample.Criteria criteria = productInfoExample.createCriteria();
//3拼接条件
if(dto.getPName()!=null &&!dto.getPName().equals("")){
criteria.andPNameLike("%"+dto.getPName()+"%");
}
if (dto.getTypeId()!=0){
criteria.andTypeIdEqualTo(dto.getTypeId());
}
if (dto.getLowPrice()>=0){
criteria.andPPriceGreaterThanOrEqualTo(dto.getLowPrice());
}
if (dto.getHighPrice()>0){
criteria.andPPriceLessThanOrEqualTo(dto.getHighPrice());
}
List<ProductInfo> productInfos = productInfoMapper.selectByExample(productInfoExample);
//3把分页需要数据撞到大对象中
PageInfo<ProductInfo> productInfoPageInfo = new PageInfo<>(productInfos);
return ResultBean.success(productInfoPageInfo);
debug查询出pageSize为18
更改PageHelper的版本等都无效,整了一个小时,哭死。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
原因:
配置好依赖后,没有在配置文件中设置plugins,没有配置方言,
因为pagehelper的原理就是给sql语句加 limit ?,? 条件,然而没有配置方言,所以并没有加上limit,也就导致最后查出来的是数据的条数。
最后在mybatis.xml中配置plugins就可以了
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="helpDialect" value="mysql"/><!--根据不同数据库语言添加分页方式-->
<!-- <property name="" value=""/>-->
<!-- <property name="" value=""/>-->
</plugin>
</plugins>
分页插件PageHelper工作原理