时间:2020-11-26 22:53:19 | 栏目:JAVA代码 | 点击:次
1 ,service 层代码实现
Integer start = (pageNum - 1) * pageSize; Integer end = pageSize; List<entity> entityList; //调用mapper查询数据库 entityList = entityPOMapper.query(start, end); SimplePageInfo simplePageInfo = SimplePageInfo.of(entityList ); simplePageInfo.setNumber(pageNum); simplePageInfo.setPageSize(pageSize); // 查询出来数据等于size,总数据量加一,页数加一 if (entityList .size() == pageSize) { Integer totalElements = (pageNum * pageSize) + 1; Integer pages = pageNum + 1; simplePageInfo.setTotalElements(totalElements); simplePageInfo.setPages(pages); } else { //数据不够size Integer totalElements = ((pageNum - 1) * pageSize + entityList .size()); Integer pages = pageNum; simplePageInfo.setTotalElements(totalElements); simplePageInfo.setPages(pages); } return simplePageInfo; }
2,mapper
<select .............> select.. from ... where ... LIMIT #{start}, #{end} </select>