Dao层:
//离线查询
public List<Emp> findByDet(DetachedCriteria c){
return c.getExecutableCriteria(HibernateSessionFactory.getSession()).list();
}
//BIz业务层
//离线查询
public List findByDet(){
DeptDao dao=new DeptDao();
DetachedCriteria c=DetachedCriteria.forClass(Emp.class,"c")
.setProjection(
Projections.projectionList()
.add(Projections.count("empno"))
//.add(Property.forName("job"))
.add(Projections.avg("sal"),"avg")
.add(Projections.max("sal"))
.add(Projections.min("sal"))
//.add(Projections.groupProperty("dept.deptno"))//dept会返回完整的deptno
.add(Property.forName("dept.deptno").group())
)
//加上条件后的离线查询
.add(Restrictions.gt("dept.deptno",(byte)10))
.addOrder(Order.asc("avg"));
return dao.findByDet(c);
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-28 23:33:20