package demo5.dao;
import demo5.entity.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;
import java.util.List;
public class manageUser {
public static void main(String[] args) {
Configuration config = new Configuration().configure();
SessionFactory sessionaFactory = config.buildSessionFactory();
Session session = sessionaFactory.openSession();
Transaction t = session.beginTransaction();
String hql = "from User";
Query query = session.createQuery(hql);
int page = 2; //输出2页
for (int i = 0; i < page; i++){
System.out.println("page="+i);
query.setFirstResult(i*5);
query.setMaxResults(5);
List<User> user = query.list();
for(User u:user){
System.out.println(u);
}
}
t.commit();
session.close();
sessionaFactory.close();
}
}
结果