Controller
@RequestMapping("/goodList")
@ResponseBody
public String goodList(@RequestParam Map < String,Object> map1){
//默认每页10条
int pageSize = 10;
//默认第一页 计算开始条数
int currentPage = 1;
//获取页面传来每页显示条数
String row = (String) map1.get("rows");
//获取页面传来当前页码
String page = (String) map1.get("page");
if(null!=row&&!"".equals(row)){
pageSize=Integer.valueOf(row);
}
if(null!=page&&!"".equals(page)){
currentPage= Integer.valueOf(page);
}
//每页从第几条开始,第几条结束
int start = (currentPage-1)*pageSize+1;
int end = currentPage*pageSize;
//总共多少条记录
int total = goodsInfoService.getCount();
List listByPage = goodsInfoService.findByPage(start, end);
JSONObject result = new JSONObject();
result.put("total", total);
result.put("rows", listByPage);
String strJson = result.toJSONString();
return strJson;
}
Service
//查询所有记录数
public int getCount(){
return goodsInfoMapper.getCount();
}
Mapper(重点,容易出错的地方)
public List findByPage(@Param("start")int start,@Param("end") int end);//分页查询
Mapper.xml(重点是大于等于,小于等于)
select
gid gid,
gname gname,
gcid gcid,
gunit gunit,
gpin gpin,
gpout gpout,
gamount gamount
from (select rownum num,
gid gid,
gname gname,
gcid gcid,
gunit gunit,
gpin gpin,
gpout gpout,
gamount gamount
from mw_pos.goodsinfo
where rownum <= #{end}) a
where a.num >= #{start}