public int getCountJsql(String pojo)
{
Query q = getSession().createQuery("select count(*) from " + pojo);
List cc = q.list();
Long a = (Long) cc.get(0);
return a.intValue();
}
cc.get(0)返回的是Long型,如果写成Integer就会报错
本文介绍了一种通过Hibernate框架获取数据库中特定表记录总数的方法。使用提供的代码片段,可以通过传递表名来创建一个查询,该查询返回指定表中的记录数量。需要注意返回的数据类型为Long,若转换为Integer类型可能会引发错误。
public int getCountJsql(String pojo)
{
Query q = getSession().createQuery("select count(*) from " + pojo);
List cc = q.list();
Long a = (Long) cc.get(0);
return a.intValue();
}
cc.get(0)返回的是Long型,如果写成Integer就会报错

被折叠的 条评论
为什么被折叠?
