表格等分页查询 后台控制器的操作

来源:互联网 发布:应用统计学专业知乎 编辑:程序博客网 时间:2024/05/01 13:06
页查询的步骤:对于一个分页查询的表格。
请求到达后台后,会默认传递两个参数  rows每页的记录条数   page当前的页
1.计算page页的偏移量  offeset = (page - 1) * rows
2.countSql=SELECT count(*) FROM ( " +  sql + " )查询出记录的总数
long totalRecords = jdbcTemplate.queryForObject(countSql,null,Long.class);//返回记录的总数
3.计算double totalPages = Math.ceil(totalRecords * 1d / limit);//获取总页码数
4.查询当前页对应记录的范围
select * from(select temp.*, ROWNUM num from (  sql )temp) where NUM>=offeset and
NUM < (offeset + rows)
4.返回即可Pagination<Map<String, Object>> pages = new Pagination<Map<String, Object>>((long)totalPages, offset, limit, totalRecords, items);

0 0
原创粉丝点击