日期:2014-05-19 浏览次数:20745 次
public List getPersonList(int max, int whichpage) { try { int index = (whichpage - 1) * max; Query query = em.createQuery("from Person p order by personid asc"); List list = query.setMaxResults(max).setFirstResult(index).getResultList(); em.clear();// 分离内存中受EntityManager管理的实体bean,让VM进行垃圾回收 return list; } catch (Exception e) { e.printStackTrace(); return null; } }
public String getLimitString(String querySelect, int offset, int limit) { if ( offset > 0 ) { throw new UnsupportedOperationException( "query result offset is not supported" ); } return new StringBuffer( querySelect.length() + 8 ) .append( querySelect ) .insert( getAfterSelectInsertPoint( querySelect ), " top " + limit ) .toString(); }