标签:pos 绑定 list pre max .com select 分页查询 content
Session session=HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx=session.beginTransaction(); List<People> peoples=session.createQuery("from People").list(); for(People people:peoples){ System.out.println(people.getName()); } tx.commit();
Session session=HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx=session.beginTransaction(); //1、依照位置进行參数绑定 /*Query query=session.createQuery("from People Where name=?"); query.setString(0,"小明1"); */ //2、依照參数名进行參数绑定 Query query=session.createQuery("from People Where name=:name"); query.setString("name","小明1"); List<People> peoples=query.list(); for(People people:peoples){ System.out.println(people.getName()); } tx.commit();
Session session=HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx=session.beginTransaction(); Query query=session.createQuery("from People"); query.setFirstResult(0);//设置查询開始的起始位置 query.setMaxResults(2);//设置查询的数目 List<People> peoples=query.list(); for(People people:peoples){ System.out.println(people.getName()); } tx.commit();
Session session=HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx=session.beginTransaction(); //count() Query query=session.createQuery("select count(*) from People"); long count=(long) query.uniqueResult(); System.out.println(count); tx.commit(); //min() max() avg() sum()的使用与count相似
Session session=HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx=session.beginTransaction(); String names[]={"小明1","小明2","小明3"}; Query query=session.createQuery("from People where name in (:name)"); query.setParameterList("name",names); List<People> peoples=query.list(); for(People people:peoples){ System.out.println(people.getId()); } tx.commit();
标签:pos 绑定 list pre max .com select 分页查询 content
原文地址:http://www.cnblogs.com/wzzkaifa/p/7398796.html