// 简化代码,定义一个用户列表分页共用方法
public String showUsers(HttpServletRequest request,
HttpServletResponse response) {
//List<User> users = manageService.getUsers();
Integer count = manageService.getUserCount(); //获取表数据的总数目
System.out.println("count"+count);
Integer pageSize = count / 10 + ((count % 10) == 0 ? 0 : 1);
String pageNowstr = request.getParameter("pageNow");
Integer pageNow;
if (null == pageNowstr)
pageNow = 1;
else
pageNow = Integer.parseInt(pageNowstr);
pageNow = pageNow > pageSize ? pageSize : pageNow;
Integer pageStart = 1;
Integer pageEnd = 11;
if (pageNow > 6) {
pageStart = pageNow - 5;
pageEnd = pageNow + 5;
}
if (pageEnd > pageSize) {
pageEnd = pageSize;
pageStart = (pageEnd - 10) < 0 ? 1 : (pageEnd - 10);
}
Integer start = (pageNow - 1) * 10;
Integer end = (start + 10) > count ? count : (start + 10);
/*users = users.subList(start, end);
*
request.getSession().setAttribute("users", users);*/
Integer begin=(pageNow-1)*10;
if(begin==0) begin=1;
List<User> users=manageService.getUserLimit(begin); //分页查询获得当前要显示的10条数据
request.getSession().setAttribute("pageSize", pageSize);//总共页数
request.getSession().setAttribute("pageNow", pageNow);//当前页
request.getSession().setAttribute("pageStart", pageStart);//起始页
request.getSession().setAttribute("pageEnd", pageEnd);//最后一页
request.getSession().setAttribute("users", users);// 存到session域,jsp页用${}表达式获取显示
return "manage/users"; //返回到分页显示页面
}