这是个hibernate QBC 分页方法 public class CustometImpl extends DAO implements Icst_customer { @SuppressWarnings("unchecked")
public List<CstCustomer> findAllCstCustomer(final CstCustomer customer,
final int page, final int row) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
@SuppressWarnings("finally")
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
try {
Criteria c = session.createCriteria(CstCustomer.class); if (customer != null)
c.add(Example.create(customer).enableLike(
MatchMode.ANYWHERE).excludeNone()
.excludeZeroes()); c.setFirstResult((page - 1) * row);
c.setMaxResults(row); List<CstCustomer> list = c.list(); int count = (Integer) c.setProjection(
Projections.rowCount()).uniqueResult();
// c.setProjection(null); int ye = 0;
if (count % row == 0)
ye = count / row;
else
ye = count / row + 1; List list1 = new ArrayList();
list1.add(list);
list1.add(count);
list1.add(ye);
return list1;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
session.close();
}
}
});
} 第一次 页面加载的时候正常 但是 点击分页按钮 例如上一页 或者跳转,
也就是说第二次调用上面方法的时候 就会提示
int count = (Integer) c.setProjection(Projections.rowCount()).uniqueResult(); 是null 高手来帮下忙 。感谢!
public List<CstCustomer> findAllCstCustomer(final CstCustomer customer,
final int page, final int row) {
return getHibernateTemplate().executeFind(new HibernateCallback() {
@SuppressWarnings("finally")
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
try {
Criteria c = session.createCriteria(CstCustomer.class); if (customer != null)
c.add(Example.create(customer).enableLike(
MatchMode.ANYWHERE).excludeNone()
.excludeZeroes()); c.setFirstResult((page - 1) * row);
c.setMaxResults(row); List<CstCustomer> list = c.list(); int count = (Integer) c.setProjection(
Projections.rowCount()).uniqueResult();
// c.setProjection(null); int ye = 0;
if (count % row == 0)
ye = count / row;
else
ye = count / row + 1; List list1 = new ArrayList();
list1.add(list);
list1.add(count);
list1.add(ye);
return list1;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
session.close();
}
}
});
} 第一次 页面加载的时候正常 但是 点击分页按钮 例如上一页 或者跳转,
也就是说第二次调用上面方法的时候 就会提示
int count = (Integer) c.setProjection(Projections.rowCount()).uniqueResult(); 是null 高手来帮下忙 。感谢!
解决方案 »
- 购物车到订单
- org.hibernate.MappingNotFoundException: resource: com.menglei.shili/msg.hbm.xml
- 我做一个网站 想不用注册会员 直接用QQ账号登录网站
- Servlet里 的 <a href="file:///.. 超链接片段点击没反应
- 处理大字段时tomcat出现错误日志(oracle数据库),只能保存部分信息?
- 请教TomCat启动问题
- 怎样用JFreeChart的setToolTipGenerator()方法
- 简单的JS,怎么就是没人肯帮看看`...
- 为什么后台不能显示前台页面发送过来的数据(Jsp)
- 我每次进行增加删除更新查询操作都会报这个错,怎么解决
- 怎样把signature.sign()生成的签名加入文件
- servlet
Criteria c2 = session.createCriteria(CstCustomer.class);