计算总页数的两种小技巧 /*获取总页数的第一种技巧:*/ //每页显示的记录数 int pageCount = 2; //从数据库获得总共的条数int totalCount = Dao.findCount();//计算总共的页数int totalPage = (totalCount%
/*获取总页数的第一种技巧:*/
//每页显示的记录数
int pageCount = 2;
//从数据库获得总共的条数
int totalCount = Dao.findCount();
//计算总共的页数
int totalPage = (totalCount%pageCount)==0?(totalCount/pageCount):(totalCount/pageCount)+1;
/*获取总页数的第二种技巧:*/
//注意下面的类型
double tc = totalCount;
Double num = Math.ceil(tc / totalCount);//向上取整
totalPage = num.intValue();
