1 ,service 层代码实现
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
|
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
1
2
3
4
5
6
|
<select .............>
select..
from ...
where ...
limit #{start}, #{end}
</select>
|
以上所述是小编给大家介绍的java仿百度假分页代码实现详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!