日期:2014-05-20 浏览次数:20621 次
public interface BaseService { /** * 根据HQL查询数据库 * @param hql * @return */ public List findByHql(String hql); }
public class BaseServiceImpy implements BaseService { private BaseDao baseDao; public List findBySql(String sql) { return this.baseDao.findBySql(sql); //这里baseDao == null } //setter, getter public BaseDao getBaseDao() { return baseDao; } public void setBaseDao(BaseDao baseDao) { this.baseDao = baseDao; } }
public interface SysActionService extends BaseService{ //未定义任何方法,调用BaseService中的方法 }
public class SysActionServiceImpy extends BaseServiceImpy implements SysActionService{ private static Log log = LogFactory.getLog(SysActionService.class); private SysActionDao sysActionDao; public SysActionDao getSysActionDao() { return sysActionDao; } public void setSysActionDao(SysActionDao sysActionDao) { this.sysActionDao = sysActionDao; } }
<bean id="baseDao" class="com.dao.impy.BaseDaoImpy"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="baseService" class="com.impy.BaseServiceImpy"> <property name="baseDao" ref="baseDao"></property> </bean> <bean id="sysActionDao" class="com.dao.impy.SysActionDaoImpy"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="sysActionService" class="com.service.impy.SysActionServiceImpy"> <property name="sysActionDao" ref="sysActionDao" /> </bean>
sysActionService.findByHql("from SysAction");
<bean id="sysActionDao" class="com.dao.impy.SysActionDaoImpy"> <property name="sessionFactory" ref="sessionFactory" /> <property name="baseDao" ref="baseDao"></property> </bean>