记录写过的Dao语句 有HQL的 有SQL的 有Criteria的
@Repository public class GuahaoManagerDaoImpl extends HibernateDaoSupport implements GuahaoManagerDao { @Autowired public void setsessionFactory(SessionFactory sessionFactory){ super.setSessionFactory(sessionFactory); } public void addGuhao(GuahaodanEntity guahaodanEntity) { this.getHibernateTemplate().save(guahaodanEntity);// TODO Auto-generated method stub } public GuahaodanEntity findById(int id) { return (GuahaodanEntity) this.currentSession() .createQuery( "from GuahaodanEntity where id = ? and isused = true") .setParameter(0, (Integer)id).uniqueResult(); } @Override public List findAll(int begin, int pageSize) { DetachedCriteria detachedCriteria=DetachedCriteria.forClass(GuahaodanEntity.class).add(Restrictions.eq("isused",true)); List guahaodanEntities= (List ) getHibernateTemplate().findByCriteria(detachedCriteria,begin,pageSize); return guahaodanEntities; } @Override public List findAllCount() { DetachedCriteria detachedCriteria=DetachedCriteria.forClass(GuahaodanEntity.class).add(Restrictions.eq("isused",true)); List guahaodanEntities= (List ) getHibernateTemplate().findByCriteria(detachedCriteria); return guahaodanEntities; } @Override public void modifyGuhao(GuahaodanEntity guahaodanEntity) { this.getHibernateTemplate().saveOrUpdate(guahaodanEntity); } public void delGuhao(int id) { this.getHibernateTemplate().delete(getSessionFactory().getCurrentSession().createCriteria(GuahaodanEntity.class).add(Restrictions.eq("id",id)).uniqueResult()); } } //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————-
@Repository public class DoctorManagerDaoImpl extends HibernateDaoSupport implements DoctorManagerDao { @Autowired public void setsessionFactory(SessionFactory sessionFactory){ super.setSessionFactory(sessionFactory); } @Override public List findByPage(int begin, int pageSize, Integer id) { DetachedCriteria detachedCriteria=DetachedCriteria.forClass(DoctorEntity.class); detachedCriteria.add(Restrictions.sqlRestriction("cl_do_id="+id)); List doctorEntities= (List ) getHibernateTemplate().findByCriteria(detachedCriteria,begin,pageSize); return doctorEntities; } @Override public List findAll(Integer id) { Session session=getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(DoctorEntity.class); criteria.add(Restrictions.sqlRestriction("cl_do_id="+id)); List doctorEntities=criteria.list(); return doctorEntities; } @Override public void addDoctor(DoctorEntity doctorEntity) { this.getHibernateTemplate().save(doctorEntity); } @Override public DoctorEntity findById(int id) { return getHibernateTemplate().get(DoctorEntity.class,id); } }