首页 > 代码库 > Hibernate中的QBC查询
Hibernate中的QBC查询
QBC 查询方式(Query By Criteria)
public void testQBCQuery1(){ Criteria criteria=session.createCriteria(Student.class); List<Student> studentList=criteria.list(); Iterator it=studentList.iterator(); while(it.hasNext()){ Student s=(Student)it.next(); System.out.println(s); } }
public void testQBCQuery2(){ Criteria criteria=session.createCriteria(Student.class); Criterion c1=Restrictions.like("name", "何%"); Criterion c2=Restrictions.eq("age", 20); criteria.add(c1); criteria.add(c2); List<Student> studentList=criteria.list(); Iterator it=studentList.iterator(); while(it.hasNext()){ Student s=(Student)it.next(); System.out.println(s); } }
public void testQBCQuery3(){ Criteria criteria=session.createCriteria(Student.class); criteria.addOrder(Order.desc("age")); List<Student> studentList=criteria.list(); Iterator it=studentList.iterator(); while(it.hasNext()){ Student s=(Student)it.next(); System.out.println(s); } }
public void testQBCQuery4(){ Criteria criteria=session.createCriteria(Student.class); criteria.setFirstResult(2); criteria.setMaxResults(2); List<Student> studentList=criteria.list(); Iterator it=studentList.iterator(); while(it.hasNext()){ Student s=(Student)it.next(); System.out.println(s); } }
public void testQBCQuery5(){ Criteria criteria=session.createCriteria(Student.class); criteria.setFirstResult(2); criteria.setMaxResults(1); Student student=(Student)criteria.uniqueResult(); System.out.println(student); }
public void testQBCQuery6(){ Criteria criteria=session.createCriteria(Student.class); List<Student> studentList=criteria .setFirstResult(0) .setMaxResults(2) .list(); Iterator it=studentList.iterator(); while(it.hasNext()){ Student s=(Student)it.next(); System.out.println(s); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。