分页返回json格式数据
分页⼯具类PageBean.java
package org.activeii.activeii.app.person.util;
engagedimport 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;// 结束debug是什么意思
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;
} el {
this.pageSize = 1;
}
/
/ 判断页数和当前页数
if (pageIndex > pageSize) {
pageIndex = pageSize;
}
if (pageIndex < 1) {
pageIndex = 1;
}
// 根据当前页计算起始和结束条⽬
this.start = (pageIndex - 1) * pageCount + 1;
}
public PageBean(int pageIndex, int count, int pageCount) {
super();
this.pageIndex = pageIndex;
this.pageCount = pageCount;
}
public PageBean(int pageIndex, int count, int pageCount, List<T> list) {
super();
this.pageIndex = pageIndex;
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 tPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public int getPageSize() {
return pageSize;
}
public void tPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCount() {
return count;
}
public void tCount(int count) {
}
public int getPageCount() {
return pageCount;
}
public void tPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getStart() {
return start;
}
public void tStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void tEnd(int end) {
}
public List<T> getList() {
return list;
}
public void tList(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.city_location AS "cityLocation",
2014年高考数学试卷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>
<lect id="queryListPage"永不言败的意思
parameterType="java.lang.Integer" resultMap="financialResult">
lect
<include refid="financialColumns" />
from yryz_financial a limit #{start},#{end}
</lect>
dao层
public List<Financial> queryListPage(@Param("start") int start, @Param("end") int end);
rvice层
public List<Financial> queryListPage(int start, int end);
rvice impl层
public PageInfo<Financial> queryFinancialList(FinancialDto financialDto){
PageHelper.PageNo(), PageSize());
List<Financial> list = financialDao.queryAll();
PageInfo<Financial> page = new PageInfo<Financial>(list);
return page;
}
controller层
@ResponBody
@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.lectCount(), 2); pb.init();
List<Financial> financiallist = financialService.queryListPage(start, end);
if (null != financiallist && financiallist.size() > 0) {
pb.tList(financiallist);
map.put("data", pb);
map.put("message", "success");
} el {
map.put("message", "fail");
}
return map;
}
结果
八年级上册英语课本{
"data": {
"count": 3,
"end": 2,
"list": [
{
"account": "KM",
"appName": "activeii",
"applyTime": 1489614237000,
myfather"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",
thestatueofliberty"qualificationClassify": "KM3",
"qualificationNum": "KM3",
"qualificationStatus": 1,
"revision": 1
}
],
"pageCount": 2,
"pageIndex": 1,
"pageSize": 2,
"start": 1
},
"message": "success"
}