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)); } }
时间: 2024-04-11 11:31:18 浏览: 16
这段代码是一个构造函数,它接受一个包含数据行、总数和每个页面的信息的参数,并根据这些信息初始化一个分页对象。
构造函数中的逻辑主要是根据总数和每页大小计算出总页数,并根据当前页码判断是否为第一页或最后一页。然后根据总页数的不同情况,生成页面列表。
如果总页数小于5,将1到总页数的数字依次添加到页面列表中。如果总页数大于5,将当前页码前后2个页码添加到页面列表中。如果总页数等于5,则直接将1到5添加到页面列表中。
最后,将计算得到的各个属性赋值给分页对象的成员变量。
相关问题
如何将mysql查询的返回值list<Row>数据类型转换成list<map>的数据类型
你可以遍历list<Row>,然后将每个Row对象转换成一个Map对象,将Map对象添加到list<map>中。具体代码如下:
```java
List<Row> rows = mysqlQuery(); // 假设这里是查询mysql返回的list<Row>
List<Map<String, Object>> result = new ArrayList<>();
for (Row row : rows) {
Map<String, Object> map = new HashMap<>();
for (Column column : row.getColumns()) {
map.put(column.getName(), column.getValue());
}
result.add(map);
}
```
在上面的代码中,假设Row对象有一个getColumns()方法,返回一个包含Column对象的列表,Column对象有getName()和getValue()方法,分别返回列名和列值。我们遍历list<Row>,将每个Row对象转换成一个Map对象,然后将Map对象添加到list<map>中。
List<sqlRows>转换成List<StaffInfoExcel>
你好!让我来帮助你解答这个问题吧。针对这个问题,你可以使用Java Stream中的map()方法和Stream API完成列表的转换。具体步骤如下:
1.定义两个类sqlRows和StaffInfoExcel,分别表示需要转换的两个对象。
2.定义一个方法,接收一个List<sqlRows>的参数,并返回List<StaffInfoExcel>。
3.使用Stream API将List<sqlRows>转换成Stream<sqlRows>对象。
4.调用map()方法将Stream<sqlRows>映射成Stream<StaffInfoExcel>。
5.使用collect()方法将Stream<StaffInfoExcel>转换成List<StaffInfoExcel>对象。
示例代码如下:
```
public class Converter {
public List<StaffInfoExcel> convert(List<sqlRows> rows) {
return rows.stream()
.map(row -> new StaffInfoExcel(row.getField1(), row.getField2(), row.getField3()))
.collect(Collectors.toList());
}
}
public class sqlRows {
private String field1;
private int field2;
private double field3;
// 省略getter、setter方法
}
public class StaffInfoExcel {
private String name;
private int age;
private double salary;
public StaffInfoExcel(String name, int age, double salary) {
this.name = name;
this.age = age;
this.salary = salary;
}
// 省略getter、setter方法
}
```
以上就是将List<sqlRows>转换成List<StaffInfoExcel>的方法,希望能够对你有所帮助。如果还有其他问题,可以继续问我哦!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)