使用分页显示列表
发布时间:2020-12-14 04:42:53 所属栏目:大数据 来源:网络整理
导读://使用分页//1.计算总页数,StudentBizImpl bb = new StudentBizImpl();int pageSize = 5;//每页显示记录数int count = bb.getStudentCount();//总记录数计算总页数int totalpages= (count%pageSize ==0)?(count/pageSize):(count/pageSize+1);//获取当前页S
//使用分页 //1.计算总页数, StudentBizImpl bb = new StudentBizImpl(); int pageSize = 5;//每页显示记录数 int count = bb.getStudentCount();//总记录数计算总页数 int totalpages= (count%pageSize ==0)?(count/pageSize):(count/pageSize+1); //获取当前页 String currentPage = request.getParameter("pageIndex"); if(currentPage==null){ currentPage = "1"; } int pageIndex = Integer.parseInt(currentPage);//强转为int,便于计算 //计算开始索引 if(pageIndex < 1){ pageIndex = 1; }else if(pageIndex > totalpages){ pageIndex = totalpages; } int stateIndex = pageSize*(pageIndex-1)+1; //结束 int endIndex = pageSize*pageIndex; String search =""; if(request.getParameter("search")!=null){ search = request.getParameter("search"); } List<Student> studentList = bb.getList(stateIndex,endIndex); request.setAttribute("studentList",studentList); request.setAttribute("pageIndex",pageIndex); request.setAttribute("totalpages",totalpages); request.getRequestDispatcher("studentList.jsp").forward(request,response); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |