用注释方式编写Spring 的代理类存储方法

@Repository("fxyDao")

public class FxyDaoImpl extends HibernateDaoSupport  implements FxyDao{

//以下内容必须写入,才可以使用HibernateDaoSupport中的各种代理方法

private SessionFactory mySessionFacotry;
@Resource
public void setMySessionFacotry(SessionFactory sessionFacotry) {
this.mySessionFacotry = sessionFacotry;
}
@PostConstruct
public void injectSessionFactory() {
super.setSessionFactory(mySessionFacotry);
}


public List<TBasEnterprise> findAllTBasEnterprise() throws Exception{
String hql = "from TBasEnterprise";
System.out.println(1);
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
System.out.println(2);
list = this.getHibernateTemplate().find(hql);
System.out.println(3);
return list;
}


public List<TBasEnterprise> findAllTBasEnterprise(final int page,final int pageSize)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "from TBasEnterprise";
Query query = session.createQuery(hql);
query.setFirstResult((page-1)*pageSize);
query.setMaxResults(pageSize);
return query.list();
}
});
return list;
}
@Override
public List<TBasEnterprise> findAllTBasEnterprise(final Page page,final String hql)
throws Exception {
List<TBasEnterprise> list = new ArrayList<TBasEnterprise>();
list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
query.setFirstResult((page.getNowPage()-1)*page.getPageSize());
query.setMaxResults(page.getPageSize());
return query.list();
}
});
return list;
}

@Override
public String getStringValue(final String sql) throws Exception {
// TODO Auto-generated method stub

List<String> list  = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}

@Override
public int getRowsBySql(final String sql) throws Exception {
List<Integer> list  = this.getHibernateTemplate().executeFind(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});
return list.get(0);
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值