接口
List queryStudentsByArray(int currPage, int pageSize);
实现接口
@Override
public List queryStudentsByArray(int currPage, int pageSize) {
//查询全部数据
List students = studentMapper.queryStudentsByArray();
//从第几条数据开始
int firstIndex = (currPage - 1) * pageSize;
//到第几条数据结束
int lastIndex = currPage * pageSize;
return students.subList(firstIndex, lastIndex); //直接在list中截取
}
controller
@ResponseBody
@RequestMapping("/student/array/{currPage}/{pageSize}")
public List getStudentByArray(@PathVariable("currPage") int currPage, @PathVariable("pageSize") int pageSize) {
List student = StuServiceIml.queryStudentsByArray(currPage, pageSize);
return student;
}
sql分页
mybatis接口
List queryStudentsBySql(Map data);
xml文件
service
接口
List queryStudentsBySql(int currPage, int pageSize);
实现类
public List queryStudentsBySql(int currPage, int pageSize) {
Map data = new HashedMap();
data.put("currIndex", (currPage-1)*pageSize);
data.put("pageSize", pageSize);
return studentMapper.queryStudentsBySql(data);
}
List getAllBookByPage(@Param("currPage")Integer pageNo,@Param("pageSize")Integer pageSize);
acc.id, acc.cateCode, cate_name, user_id,u.name as user_name, money, remark, time
service
public List getAllBookByPage(String pageNo,String pageSize) {
return accountMapper.getAllBookByPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
}
controller
@RequestMapping("/getAllBook")
@ResponseBody
public Page getAllBook(String pageNo,String pageSize,HttpServletRequest request,HttpServletResponse response){
pageNo=pageNo==null?"1":pageNo; //当前页码
pageSize=pageSize==null?"5":pageSize; //页面大小
//获取当前页数据
List list = bookService.getAllBookByPage(pageNo,pageSize);
//获取总数据大小
int totals = bookService.getAllBook();
//封装返回结果
Page page = new Page();
page.setTotal(totals+"");
page.setRows(list);
return page;
}
Page实体类
package com.autumn.pojo;
import java.util.List;
/**
* Created by Autumn on 2018/6/21.
*/
public class Page {
private String pageNo = null;
private String pageSize = null;
private String total = null;
private List rows = null;
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
public String getPageNo() {
return pageNo;
}
public void setPageNo(String pageNo) {
this.pageNo = pageNo;
}
public String getPageSize() {
return pageSize;
}
public void setPageSize(String pageSize) {
this.pageSize = pageSize;
}
}
public List queryUsersByPage(String userName, RowBounds rowBounds);
service
@Override
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.SUPPORTS)
public List queryRolesByPage(String roleName, int start, int limit) {
return roleDao.queryRolesByPage(roleName, new RowBounds(start, limit));
}