在一个DaoImpl实现中调用另一个DaoImpl中的方法

1、被调用的Dao接口

public interface IFieldDescriptionDao {
    public List<String> getFieldDescription(Connection conn,String tableName)throws SQLException; 
}

2、被调用的DaoImpl实现

public class FieldDescriptionDaoImpl implements IFieldDescriptionDao{
    
    public List<String> getFieldDescription(Connection conn,String tableName)throws SQLException{//获取字段的中文说明,作为标题行在页面展示
        return fieldsList;
    }
}

3、调用的DaoImpl实现

import com.dao.IFieldDescriptionDao;

public class CommunicationStatDaoImpl implements ICommunicationStatDao{

  private  IFieldDescriptionDao fieldDescriptionDao;  //声明另一个Dao字段说明

  public List<List<String>> queryCommunicationList(Connection conn, int pageSize, int currPage) throws SQLException {
       
          List<List<String>> list = new ArrayList<List<String>>();
     
          list.add(fieldDescriptionDao.getFieldDescription(conn,"JT_CommunicationStatus"));//调用方法

    return list;
    }

  //要生成Get/Set方法,要不实例对象为空

  public IFieldDescriptionDao getFieldDescriptionDao() { //get方法
        return fieldDescriptionDao;
     }

    public void setFieldDescriptionDao(IFieldDescriptionDao fieldDescriptionDao) { //set方法
        this.fieldDescriptionDao = fieldDescriptionDao;
    }

}

4、在调用的配置文件中,

<bean name="communicationDao" class="com.chatone.dao.CommunicationStatDaoImpl">
    <property name="fieldDescriptionDao" ref="fieldDescriptionDao"/>  //被调用实例属性
</bean>


     

原文地址:https://www.cnblogs.com/limeiky/p/12512102.html