PageHelper:分页插件

发布于 2021-09-09  1272 次阅读


先上代码,这段是实习公司用的分页代码,第一看的时候很懵逼,研究了下,做个记录。

String whereSql = CommonMethod.getWhereSql(conditionObj);
PageHelper.startPage((bootPage.getOffset()/10+1), bootPage.getLimit());
List<FourUpCompany> list = fourUpDao.getFourUpInfo(bootPage, fourUpCompany, whereSql,keyword,industrycodeid,tagid);
PageInfo pageInfo = new PageInfo(list);
return new BootPage<>(bootPage.getOffset(), bootPage.getLimit(), pageInfo.getTotal(), list);

第一行:String whereSql = CommonMethod.getWhereSql(conditionObj);

这是高级查询封装,传相关字段和数据过来,后台封装成sql语句,最后拼接到sql中形成完成的查询

第二行:PageHelper.startPage((bootPage.getOffset()/10+1), bootPage.getLimit());

PageHelper是一个分页插件,startPage的第一个参数是页数,第二个参数是分页大小,并且只对下一行查询有效。

作者有相关说明:https://pagehelper.github.io/docs/howtouse/

第三行:查询,会被插件封装分页

第四行:PageInfo pageInfo = new PageInfo(list); 转化为PageInfo对象,方便拿出相关分页数据

第五行:new BootPage<>(bootPage.getOffset(), bootPage.getLimit(), pageInfo.getTotal(), list);BootPage是内部封装的分页显示实体。


欢迎欢迎~热烈欢迎~