在action中:
public class VoucherDeleteTable extends BaseAction {
private IEVoucherDeleteTable evoucherDeleteTable;
public IEVoucherDeleteTable getEvoucherDeleteTable() {
return evoucherDeleteTable;
}
public void setEvoucherDeleteTable(IEVoucherDeleteTable evoucherDeleteTable) {
this.evoucherDeleteTable = evoucherDeleteTable;需要注入的是服务的接口,利用服务的实例实现相应的执行方法:
1)listMap=evoucherDeleteTable.queryForPageDelete(styeay);
2)evoucherDeleteTable.delTable(delStrs[i])在Spring注入的时候需要注入的是服务接口的实现,必须是实现,这就体现了Java的多态概念。
注入方式如下:
<bean id="common.vdelete" class="assp.evoucher.sysmgr.action.VoucherDeleteTable" scope="prototype">
<property name="evoucherDeleteTable" ref="assp.EvoucherDeleteTable"></property>
</bean>
<bean id="assp.EvoucherDeleteTable" class="assp.evoucher.sysmgr.bs.EvoucherDeleteTableImpl">
<property name="evoucherbasedao" ref="evoucherdeletetabledao"></property>
</bean>这个地方的property属性是与别的业务相关的注入,这里与这里无关。
强调一点:Java代码中声明的是接口,但是具体代码中使用接口的实例实际上市接口的实现,这里的接口实现操作是通过
配置文件中控制反转和依赖注入实现的。
在业务层中:
public class EvoucherDeleteTableImpl implements IEVoucherDeleteTable {
EvoucherDeleteTableDAO evoucherbasedao;
public EvoucherDeleteTableDAO getEvoucherbasedao() {
return evoucherbasedao;
}
public void setEvoucherbasedao(EvoucherDeleteTableDAO evoucherbasedao) {
this.evoucherbasedao = evoucherbasedao;
}
@Override
public void delTable(String sqltable) {
evoucherbasedao.delTable(sqltable);
}
@Override
public List queryForPageDelete(String styeay) {
return evoucherbasedao.queryDeleteTable(styeay);
}
}Spring注入:
<bean id="assp.EvoucherDeleteTable" class="assp.evoucher.sysmgr.bs.EvoucherDeleteTableImpl">
<property name="evoucherbasedao" ref="evoucherdeletetabledao"></property>
</bean>
<bean id="evoucherdeletetabledao" class="assp.evoucher.sysmgr.dao.EvoucherDeleteTableDAO">
</bean>
evoucherbasedao.delTable(sqltable);
return evoucherbasedao.queryDeleteTable(styeay);在业务层是处理业务的地方,处理业务肯定是需要和DAO层打交道,这里也就是处理DAO层的业务逻辑,实际上就是调用DAO层的业务逻辑
以实现具体业务。
强调一点,这里的第一个<bean>体现了控制反转和依赖注入,第二个<bean>体现了控制反转
在DAO层的逻辑:
public class EvoucherDeleteTableDAO extends EVoucherBaseDAO {
public List queryDeleteTable(String styeay){
String dataBaseService = PropertiesHander.getEVConfValue(BIZConstant.DATABASE_SERVICE);
//根据年度查询
String sql = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME LIKE '%"+"_"+styeay+"%' ";
List list = this.queryForList(sql);
return list;
}
public void delTable(String sqltable) {
// TODO Auto-generated method stub
String dataBaseService = PropertiesHander.getEVConfValue(BIZConstant.DATABASE_SERVICE);
//根据表名清空表中数据
String sql="delete from "+sqltable;
this.execute(sql);
}DAO层就是相关执行sql语句与数据库打交道了
String sql = "SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME LIKE '%"+"_"+styeay+"%' ";
List list = this.queryForList(sql);
String dataBaseService = PropertiesHander.getEVConfValue(BIZConstant.DATABASE_SERVICE);
//根据表名清空表中数据
String sql="delete from "+sqltable;
this.execute(sql);
总结仍然不足,存在表达上的与逻辑上的瑕疵,这次这里没有讲到关于MODEL层的调用。仍不完善。

被折叠的 条评论
为什么被折叠?



