hibernate query和Criteria分页查询的区别

Query Q = session.createQuery("from customer as c where c.name = :customerName" + "and c.age = :customerAge");
   query.setString ("customerName" , "tom");
   query.setInteger("customerAge" , "21");
   list result = query.list();

QBC :  QBCAPI提供了另一种方式,主要是Criteria接口、Criterion接口和Expression类
   Criteria criteria = session.createCriteria(customer.class);
   Criterion criterion1 = Expression.like("name","t%");
   Criterion criterion2 = Expression.eq("age",new Integer(21));
   Critera = criteria.add(criterion1) ;
   Critera = criteria.add(criterion2) ;
   list result = criteria.list(); 
   或是: list result = session.createCriteria(Customer.class).add(Expression.eq("this.name","tom")).list(); 

你可能感兴趣的:(query)