public interface IElecTextDao extends ICommonDao<ElecText> {
public static final String SERVICE_NAME = "cn.itcast.elec.dao.impl.ElecTextDaoImpl";
}
(2)在cn.itcast.elec.dao.impl中创建对应业务接口的实现类ElecTextDaoImpl
@Repository(IElecTextDao.SERVICE_NAME)
public class ElecTextDaoImpl extends CommonDaoImpl<ElecText> implements IElecTextDao {
}
(3)在cn.itcast.elec.dao中创建对应的公用接口 ICommonDao
public interface ICommonDao<T> {
void save(T entity);
}
(4)在cn.itcast.elec.dao.impl中创建对应公用接口的实现类CommonDaoImpl,并注入sessionFactory给hibernateTemplate
public class CommonDaoImpl<T> extends HibernateDaoSupport implements ICommonDao<T> {
/**
* <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
*/
@Resource(name="sessionFactory")
public final void setSessionFactoryDi(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}