public class PersonDAOImpl extends HibernateDaoSupport implements PersonDAO { public int getAllCount() throws Exception {
int count = 0;
String hql = "SELECT COUNT(p.id) from Person AS p";
Query q = this.getSession().createQuery(hql);
List all = q.list();
if (all.size() > 0) {
count = (Integer) all.get(0);
}
return count;
} public int getByLikeCount(String cond) throws Exception {
int count = 0;
String hql = "SELECT COUNT(p.id) from Person AS p WHERE p.uid LIKE ? OR p.name LIKE ?";
Query q = this.getSession().createQuery(hql);
q.setString(0, "%" + cond + "%");
q.setString(1, "%" + cond + "%");
List all = q.list();
if (all.size() > 0) {
count = (Integer) all.get(0);
}
return count;
} public List queryAll(int currentPage, int lineSize) throws Exception {
List<Person> all = new ArrayList<Person>();
String hql = "FROM Person AS p";
Query q = this.getSession().createQuery(hql);
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return all;
} public List queryByLike(String cond, int currentPage, int lineSize)
throws Exception {
List<Person> all = new ArrayList<Person>();
String hql = "FROM Person AS p WHERE p.uid LIKE ? OR p.name LIKE ?";
Query q = this.getSession().createQuery(hql);
q.setString(0, "%" + cond + "%");
q.setString(1, "%" + cond + "%");
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return all;
}
};
int count = 0;
String hql = "SELECT COUNT(p.id) from Person AS p";
Query q = this.getSession().createQuery(hql);
List all = q.list();
if (all.size() > 0) {
count = (Integer) all.get(0);
}
return count;
} public int getByLikeCount(String cond) throws Exception {
int count = 0;
String hql = "SELECT COUNT(p.id) from Person AS p WHERE p.uid LIKE ? OR p.name LIKE ?";
Query q = this.getSession().createQuery(hql);
q.setString(0, "%" + cond + "%");
q.setString(1, "%" + cond + "%");
List all = q.list();
if (all.size() > 0) {
count = (Integer) all.get(0);
}
return count;
} public List queryAll(int currentPage, int lineSize) throws Exception {
List<Person> all = new ArrayList<Person>();
String hql = "FROM Person AS p";
Query q = this.getSession().createQuery(hql);
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return all;
} public List queryByLike(String cond, int currentPage, int lineSize)
throws Exception {
List<Person> all = new ArrayList<Person>();
String hql = "FROM Person AS p WHERE p.uid LIKE ? OR p.name LIKE ?";
Query q = this.getSession().createQuery(hql);
q.setString(0, "%" + cond + "%");
q.setString(1, "%" + cond + "%");
q.setFirstResult((currentPage - 1) * lineSize);
q.setMaxResults(lineSize);
all = q.list();
return all;
}
};
?你用的hibernate的,hibernate已经把分页的方式做到dialect里了,而不需要你考虑跨数据的转换。你需要做的只是把你hibernate有关dialect配置的地方从MysqlDialect改成OracleDialect。
if (all.size() > 0) {
count = (Integer) all.get(0); 出错
}
return count;
这里和分页没有关系,要是这行出错的话,应该是数据转型不对,我这里感觉你这样写也没有问题的呀,你设置个断点在这里看看all里的对象是什么样的对象。