jpa 分页功能1
来源:互联网 发布:韩国人和日本人知乎 编辑:程序博客网 时间:2024/04/28 22:29
1.service 层
public Result findAllAdvertise(Page page,String categoryId){ StringBuffer sql1 = new StringBuffer(); StringBuffer sql2 = new StringBuffer(); sql1.append("select count(*) from Advertise a"); sql2.append("from Advertise a where 1=1"); if(categoryId != null && !categoryId.equals("")){ sql1.append(" where a.categoryId = ?"); sql2.append(" and a.categoryId = ?"); sql2.append(" order by a.createtime desc"); page = PageUtil.createPage(page, (Long) em.createQuery(sql1.toString()).setParameter(1,categoryId).getSingleResult()); return new Result(page,em.createQuery(sql2.toString()).setParameter(1,categoryId).setFirstResult(page.getBeginIndex()).setMaxResults(page.getEveryPage()).getResultList()); }else{ sql2.append(" order by a.createtime desc"); page = PageUtil.createPage(page, (Long) em.createQuery(sql1.toString()).getSingleResult()); return new Result(page,em.createQuery(sql2.toString()).setFirstResult(page.getBeginIndex()).setMaxResults(page.getEveryPage()).getResultList()); } }
2.action 层
@RequestMapping("/webadmin/AderviseList.htm")
public String AderviseList(HttpServletRequest request){
String categoryId = request.getParameter("categoryId");
if(categoryId ==null ||categoryId.equals("")){
categoryId = (String)request.getAttribute("categoryId");
}
String currpage =request.getParameter("page");
if(currpage == null || currpage.equals("")){
currpage ="1";
}
Page page = new Page(20);
page.setCurrentPage(new Integer(currpage));
Result list = aderviseBiz.findAllAdvertise(page, categoryId);
request.setAttribute("aderviselist", list);
//查询所有类别
List categoryList = aderviseBiz.findAllAdvertiseCategory();
request.setAttribute("categoryList",categoryList);
request.setAttribute("categoryId", categoryId);
return "/webadmin/AderviseList.vm";
}
- jpa 分页功能1
- jpa分页功能2
- jpa 分页功能3
- Spring Data JPA+kkpager实现分页功能
- JPA分页
- jpa 分页
- jpa 分页
- 用泛型与反射技术封装分页功能(JPA)
- java分页功能1
- jpa 分页和查询
- JPA 分页处理
- SpringMVC jpa 分页问题
- JPA实现分页
- jpa 分页问题
- jpa分页设置
- JPA 分页查询Pageable
- jpa hibernate分页查询
- SpringData JPA 分页使用
- c++中的左值与右值
- [Python] The attribute with dynamic __dict__
- PHP SESSION 详解
- java zip打包
- android仿微信相册的效果
- jpa 分页功能1
- poj 2777 Count Color 线段树
- 绑定图片
- 字符串的朴素匹配与KMP匹配
- $.ajax()方法详解
- flex常见组件背景及边框颜色实例
- VMware workstation 10 英文版设置
- Integer的自动拆装箱的陷阱(整型数-128到127的值比较问题)
- PHP——动态生成mysql表格