/*
分页查询
sql:select * from cst_customer limit 0,2
jpql: from Customer
*/
@Test
public void testPaged(){
EntityManager entityManager = JpaUtils.getEntityManager();
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
//查询全部
//根据jpsql语句创建query查询对象
String jpql = "from Customer";
Query query = entityManager.createQuery(jpql);
/*
对参数进行赋值---分页参数
*/
//起始索引
query.setFirstResult(0);
//每页查询的条数
query.setMaxResults(2);
//发送查询,并封装结果
List list = query.getResultList();
for (Object o : list) {
System.out.println(o);
}
tx.commit();
entityManager.close();
}