本文只粘贴部分关键代码
1.简单查询
Session session = hibernateUtils.getCurrentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria= session.createCriteria(Customer.class); criteria.addOrder(Order.asc("cust_id")); List<Customer> list = criteria.list(); for(Customer c : list) { System.out.println(c); } transaction.commit();
2.分页查询
Session session = hibernateUtils.getCurrentSession(); Transaction transaction = session.beginTransaction(); Criteria criteria= session.createCriteria(LinkMan.class); criteria.setFirstResult(5); criteria.setMaxResults(5); List<LinkMan> list = criteria.list(); for(LinkMan man : list) { System.out.println(man); } transaction.commit();