extends HibernateDaoSupport 实现
Dao层代码:
数据库连接映射
@Resource(name = “sessionFactory”)
public void setSuperSessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
//id排序查询
public List<Goods> getGoodsList(){
String hql="from Goods order by id";
List<Goods> list=this.getHibernateTemplate().find(hql);
if(list!=null&&list.size()>0){
return list;
}else{
return new ArrayList<Goods>();
}
}
//条件查询
public Goods getGoods(String code) {
String hql="from Goods where code = ?";
List<Goods> list = this.getHibernateTemplate().find(hql,code);
if(list!=null&&list.size()>0){
return list.get(0);
}else{
return new Goods();
}
}
//模糊查询
public List<Object> getRuKuBits(String bits,String name) {
String hql="from RuKu r join r.goods g where 1=1 ";
if(bits!=null||"".equals(bits)){
hql=hql+"and bits like '%"+bits+"%'";
}
if(name!=null||"".equals(name)){
hql=hql+"and name like '%"+name+"%'";
}
List<Object> list=this.getHibernateTemplate().find(hql);
if(list!=null&&list.size()>0){
return list;
}else{
return new ArrayList<Object>();
}
}
//增加
public Serializable getZL(ZhiLing zl) {
Serializable save = this.getHibernateTemplate().save(zl);
return save;
}