分页查询案例

分页查询
 
 
---CONTROLLER---
 
/**
* 分页查询所有成员。
* @param page
* @param request
* @return
*/

@RequestMapping("/allStaff.do")
public String getAllStaff(String page,HttpServletRequest request)
{
if(page ==null)
{
page = 1+"";
}

request.setAttribute("page", page);
request.setAttribute("pageNum",staffService.getPageNum());
request.setAttribute("staffList", staffService.allStaff(page));
return "/allStaff.do";


}


/**
* 分页查询下一页
* @param page
* @param request
* @return
*/
@RequestMapping("/nextPage.do")
public String nextPage(String page,HttpServletRequest request){
int curPage = Integer.parseInt(page);
request.setAttribute("page", curPage+1);
request.setAttribute("pageNum",staffService.getPageNum());
request.setAttribute("staffList", staffService.allStaff(curPage+1+""));
return "/allStaff.do";
}

/**
* 分页查询前一页
* @param page
* @param request
* @return
*/

@RequestMapping("/prevPage.do")
public String prevPage(String page,HttpServletRequest request){
int curPage = Integer.parseInt(page);
request.setAttribute("page", curPage-1);
request.setAttribute("pageNum",staffService.getPageNum());
request.setAttribute("staffList", staffService.allStaff(curPage-1+""));
return "/allStaff.do";
}

 

 
 
 
 
 
 
 
---Action---
 
/**
* 分页查询成员信息
* @param page
* @return
*/
public List<Staff> allStaff(String page);


/**
* 获得页码。
* @return
*/
public int getPageNum();




/**
* 分页查询成员信息
* @param page
* @return
*/
public List<Staff> allStaff(String page){

return staffDao.allStaff(page);
}






/**
* 获得页码。
* @return
*/
public int getPageNum(){
return staffDao.getPageNum();
}

 

 
----DAO---
 
public int getPageNum();
public List<Staff> allStaff(String page) ;



/**
* 得到员工页面总页码信息。
*/
public int getPageNum() 
{
String hql="from Staff";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
int temp = query.list().size()/pageSize;//size=10
if(query.list().size()%pageSize !=0)
{
temp++;
}
return temp;
}



/**
* 分页获取所有员工,第一页的。
*/
public List<Staff> allStaff(String page) 
{
String hql="from Staff";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setFirstResult((Integer.parseInt(page)-1)*pageSize); 
query.setMaxResults(pageSize); 
return query.list();
}

 



 



转载于:https://www.cnblogs.com/luoxuehuan/p/4731607.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值