Hibeernate中的两种分页方式

来源:互联网 发布:知乎都是五毛 编辑:程序博客网 时间:2024/04/30 00:49
1.return getHibernateTemplate().executeFind(new HibernateCallback() {public Object doInHibernate(Session s) throws HibernateException {Criteria c = s.createCriteria(AskOnline.class);c.add(Restrictions.eq("boardid", new Long(bid)));c.setFirstResult(spage);c.setMaxResults(perPageNum);return c.list();}});2.final String hql ="from AskOnline a where a.boardid=? and a.isreply = 0 order by a.id desc";return getHibernateTemplate().executeFind(new HibernateCallback() {public Object doInHibernate(Session s) throws HibernateException, SQLException {Query query = s.createQuery(hql);query.setLong(0, bid);query.setFirstResult(spage);query.setMaxResults(perPageNum);List list = query.list();return list;}});

0 0
原创粉丝点击