若伊框架分页问题

OrangeWithCat Lv2

分页失效的两种情况

主查询语句返回的集合进行二次处理并重新封装(遍历操作不影响)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public Map<String, Object> list(YourEntityClass entities,
@RequestParam(value = "pageNum",required = false) String pageNum,
@RequestParam(value = "pageSize",required = false) String pageSize)
{
Map<String, Object> map = new HashMap<>();
Integer pageNumInt = 1;
if (pageNum != null) {
pageNumInt = Integer.parseInt(pageNum);
}
Integer pageSizeInt = 10;
if (pageSize != null) {
pageSizeInt = Integer.parseInt(pageSize);
}

paperInfo.setIsdown("0");
List<YourEntityClass> list = entityService.selectYourEntityClassList(entities);
List<YourEntityClass> listSort = new ArrayList<>();
int size = list.size();
int pageStart = pageNumInt == 1 ? 0 : (pageNumInt - 1) * pageSizeInt;//截取的开始位置
int pageEnd = size < pageNumInt * pageSizeInt ? size : pageNumInt * pageSizeInt;//截取的结束位置
if (size > pageStart) {
listSort = list.subList(pageStart, pageEnd);
}
if (list == null || list.size() == 0) {
map.put("total", 0);
map.put("rows", null);
map.put("code", 200);
map.put("msg","查询成功");
return map;
}
map.put("total", size);
map.put("rows", listSort);
map.put("code", 200);
map.put("msg","查询成功");
return map;
}
主查询在mybatis中的resultMap映射关系中添加了collection
1
2
3
4
5
6
7
8
9
10
public TableDataInfo list(YourEntityClass entities)
{
List<YourEntityClass> list = entityService.selectYourEntityClassList(entities);
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
rspData.setRows(list);
rspData.setTotal(list.size());
return rspData;
}
Comments