Hibernate中hql条件语句的书写方式有:
1. from Cat as cat where cat.name='Fritz'
2. from Cat as cat where cat.name=:name
3.from Cat as cat where cat.name=?
下面是面向对象的书写方式
List cats = session.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.add( Restrictions.between("weight", minWeight, maxWeight) )
.list();
这样对于hql语句的组织更加贴近于面向对象的方式
Restrictions类中含有基本的条件如: like, eq, isNull, in
对于结果集的排序可以使用
List cats = session.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.addOrder( Property.forName("name").asc() )
.list();
按照字段 正序或倒序返回结果集