重点难点:
select * from products limit 0,5 第一页,每页显示5条
总分页 公式:totalPage =(totalRecord+pageNum-1)/pageSize;
开始索引:starIndex=(pageNumber-1)*pageSize
public class pageBean<T>
private List<T> data; //分页数据(数据库查询)
/获得全部的商品条数
public int getTotalCount() throws SQLException {
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
String sql ="select count(*) from product";
Long query = (Long) runner.query(sql, new ScalarHandler()) ;
return query.intValue();
}
//分页查询所有
//获得分页的商品数据
public List<Product> findProductListForPageBean( int index,int currentCount) throws SQLException {
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
String sql ="select * from product where limit ?,?";
return runner.query(sql, new BeanListHandler<Product>(Product.class),index, currentCount) ;
}