在做的项目中有个这样的方法。返回的是一个HashMap的集合。
public static HashMap<Object, Object> findTotalDuebillBalance(Database db,
String pcCode, String districtCode, String ccCode,
String studentName,String studentCode) throws Exception
{
String sql = "select d.studentCode,sum(duebillBalance) as totalDuebillBalance " +
"\n from duebill d" +
"\n left join StudentRelation sr on sr.studentCode=d.studentCode" +
"\n left join CountyCenter cc on cc.ccCode=sr.ccCode" +
"\n where 1=1";
if(!ccCode.equals(""))
sql += "\n and sr.ccCode='"+ccCode+"'";
else if(!districtCode.equals(""))
sql += "\n and exists (select 1 from CountyCenter cc where cc.ccCode=dd.deductCcCode and cc.pccCode like '"+districtCode+"%')";
else if(!pcCode.equals(""))
sql += "\n and sr.pcCode='"+pcCode+"'";
if(!studentName.equals(""))
sql += "\n and sr.studentName like '"+studentName+"%'";
if(!studentCode.equals(""))
sql += "\n and sr.studentCode = '"+studentCode+"'";
sql += "\n group by d.studentCode";
//执行查询
DataSet ds = db.executeQuery(sql);
HashMap<Object, Object> duebillMap = new HashMap<Object, Object>();
for (int i=0;i<ds.size();i++)
{
duebillMap.put(ds.getString(i, "studentCode"),ds.getDouble(i, "totalDuebillBalance"));
}
return duebillMap;
}
然后在bo中调用时候,传入参数时候。
第一种调用
DaoMyTest.findTotalDuebillBalance(db,"","","","","",studentCode);
第二种调用
DaoMyTest.findTotalDuebillBalance(db,pcCode,districtCode,ccCode,"");
--------------------------------------------------------------------------
这个和以前学习的时候学的方法重载很像,不过这种写法更倾向于简洁的应用,不至于写很多方法。业务理解上会有点困难。