分页工具类PageBean.java
package org.activeii.activeii.app.person.util;
import java.util.List;
public class PageBean<T> {
private int pageIndex;// 当前页数
private int pageSize;// 一共的页数
private int count;// 数据条数
private int pageCount;// 每页的数据条数
private int start;// 起始数据位置
private int end;// 结束
private List<T> list = null;
public void init() {
/*
* 根count 和pageCount计算页数pageSize
*/
int pageSize_x = (int) count / pageCount;
if (count >= pageCount) {
this.pageSize = count % pageCount == 0 ? pageSize_x : pageSize_x + 1;
} else {
this.pageSize = 1;
}
// 判断页数和当前页数
if (pageIndex > pageSize) {
pageIndex = pageSize;
}
if (pageIndex < 1) {
pageIndex = 1;
}
// 根据当前页计算起始和结束条目
this.start = (pageIndex - 1) * pageCount + 1;
this.end = pageIndex * pageCount;
}
public PageBean(int pageIndex, int count, int pageCount) {
super();
this.pageIndex = pageIndex;
this.count = count;
this.pageCount = pageCount;
}
public PageBean(int pageIndex, int count, int pageCount, List<T> list) {
super();
this.pageIndex = pageIndex;
this.count = count;
this.pageCount = pageCount;
this.list = list;
}
public PageBean() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return "PageBean [count=" + count + ", end=" + end + ", result=" + list + ", pageCount=" + pageCount
+ ", pageIndex=" + pageIndex + ", pageSize=" + pageSize + ", start=" + start + "]";
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}
mapper层
<sql id="financialColumns">
a.id AS "id",
a.identification AS "identification",
a.qualification_classify AS "qualificationClassify",
a.qualification_num AS "qualificationNum",
a.company AS "company",
a.city_location AS "cityLocation",
a.good_field AS "goodField",
a.personal_profile AS "personalProfile",
a.qualification_status AS "qualificationStatus",
a.apply_time AS "applyTime",
a.authentication_time AS "authenticationTime",
a.account AS "account"
</sql>
<select id="queryListPage"
parameterType="java.lang.Integer" resultMap="financialResult">
select
<include refid="financialColumns" />
from yryz_financial a limit #{start},#{end}
</select>
dao层
public List<Financial> queryListPage(@Param("start") int start, @Param("end") int end);
service层
public List<Financial> queryListPage(int start, int end);
service impl层
public PageInfo<Financial> queryFinancialList(FinancialDto financialDto){
PageHelper.startPage(financialDto.getPageNo(), financialDto.getPageSize());
List<Financial> list = financialDao.queryAll();
PageInfo<Financial> page = new PageInfo<Financial>(list);
return page;
}
controller层
@ResponseBody
@GET
@Path("/finalistPage/{start}/{end}")
public Map<String, Object> pageCount(@PathParam("start") int start, @PathParam("end") int end) {
Map<String, Object> map = new HashMap<String, Object>();
if (start < 0) {
start = 0;
}
if (end < 0) {
end = 1;
}
int pageIndex = 0;
PageBean<Financial> pb = new PageBean<Financial>(pageIndex, financialService.selectCount(), 2);
pb.init();
List<Financial> financiallist = financialService.queryListPage(start, end);
if (null != financiallist && financiallist.size() > 0) {
pb.setList(financiallist);
map.put("data", pb);
map.put("message", "success");
} else {
map.put("message", "fail");
}
return map;
}
结果
{
"data": {
"count": 3,
"end": 2,
"list": [
{
"account": "KM",
"appName": "activeii",
"applyTime": 1489614237000,
"authenticationTime": 1489614237000,
"cityLocation": "KM1",
"company": "KM1",
"goodField": "KM1",
"id": 2,
"identification": "KM1",
"personalProfile": "KM1",
"qualificationClassify": "KM1",
"qualificationNum": "KM1",
"qualificationStatus": 1,
"revision": 1
},
{
"account": "KM3",
"appName": "activeii",
"applyTime": 1489619727000,
"authenticationTime": 1489619727000,
"cityLocation": "KM3",
"company": "KM3",
"goodField": "KM3",
"id": 3,
"identification": "KM3",
"personalProfile": "KM3",
"qualificationClassify": "KM3",
"qualificationNum": "KM3",
"qualificationStatus": 1,
"revision": 1
}
],
"pageCount": 2,
"pageIndex": 1,
"pageSize": 2,
"start": 1
},
"message": "success"
}