while(pageSize * currentPage < totalCount) { currentPage++; condition.setPage(currentPage); personRelatives.addAll(this.listByCondition(condition)); }
时间: 2024-04-18 20:30:56 浏览: 19
这段代码是一个循环,用于分页查询数据并将查询结果添加到 `personRelatives` 列表中。循环条件是当当前页数乘以每页记录数小于总记录数时,执行循环体内的操作。
在循环体内,首先将当前页数加一,然后通过设置条件对象的页数属性为当前页数,进行条件查询,并将查询结果使用 `addAll()` 方法添加到 `personRelatives` 列表中。
这段代码的作用是按照每页记录数进行分页查询,并将查询到的数据累加到 `personRelatives` 列表中,直到查询完所有的数据为止。
相关问题
public Page(List<T> rows, Integer total, Map<String, Object> eachMap) { this.echoMap = eachMap; this.total = total; this.rows = rows; this.currentPage = (Integer)eachMap.get("currentPage"); this.pageSize = (Integer)eachMap.get("pageSize"); this.totalPage = this.total % this.pageSize == 0 ? this.total / this.pageSize : this.total / this.pageSize + 1; this.firstPage = this.currentPage == 1; this.lastPage = this.currentPage == this.totalPage; this.hasPrev = this.currentPage > 1; this.hasNext = !this.lastPage; if (totalPage < 5) { for (int i = 0; i < totalPage; i++) { this.pageList.add(i + 1); } } else if(totalPage > 5) { for(int i = this.currentPage - 2; i <= this.currentPage + 2; i++) { this.pageList.add(i); } } else { this.pageList.addAll(Arrays.asList(1,2,3,4,5)); } }
这段代码是一个构造函数,它接受一个包含数据行、总数和每个页面的信息的参数,并根据这些信息初始化一个分页对象。
构造函数中的逻辑主要是根据总数和每页大小计算出总页数,并根据当前页码判断是否为第一页或最后一页。然后根据总页数的不同情况,生成页面列表。
如果总页数小于5,将1到总页数的数字依次添加到页面列表中。如果总页数大于5,将当前页码前后2个页码添加到页面列表中。如果总页数等于5,则直接将1到5添加到页面列表中。
最后,将计算得到的各个属性赋值给分页对象的成员变量。
((currentPage-1)*pageSize)
这段代码是Java计算表达式,用于将分页查询的当前页码和每页显示的记录数转换成SQL语句中的偏移量(offset)。具体来说,偏移量表示从查询结果的第几条记录开始返回结果集,它的计算方式为(currentPage-1)*pageSize。例如,如果当前页码为2,每页显示10条记录,那么偏移量就是(2-1)*10=10,表示从查询结果的第11条记录开始返回结果集。这个偏移量可以用作SQL语句中的占位符,用于限制查询结果的数量。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)