ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ @Test public void test1(){ EntityManager em = JpaUtils.getEntityManager(); EntityTransaction tx = em.getTransaction(); tx.begin(); // 查询全部 //String sql = "from com.test.domain.Customer"; //排序 //String sql = "from Customer order by id desc"; //统计 //String sql = "select count(id) from Customer "; //分页 String sql = "from Customer where name like ? "; // 创建Query查询对象 Query query = em.createQuery(sql); query.setParameter(0, "test1"); //分页 //query.setFirstResult(0); //query.setMaxResults(2); List list = query.getResultList(); for (Object obj : list){ System.out.println(obj.toString()); } tx.commit(); em.close(); } ~~~