Map mailSizeInfo=new HashMap();
try{
String sql =" select count(*) as mailCount,Mail_box_coding as mailCoding from oa_mail where ISSUANCE_ID =:userId group by Mail_box_coding";
SQLQuery sqlQuery = (SQLQuery) super.getSession().createSQLQuery(sql).setString("userId",userId);
List<Object[]> students = sqlQuery.list();
for (Iterator<Object[]> iterator = students.iterator(); iterator.hasNext();) {
Object[] mailInfo = iterator.next();
logger.info("查詢出的結果mailInfo mailCount"+mailInfo[0]+"mailCoding"+mailInfo[1]);
mailSizeInfo.put(mailInfo[1],mailInfo[0]);
}
}catch(Exception ex){
ex.printStackTrace();
throw new PageJumpException();
}
try{
String sql =" select count(*) as mailCount,Mail_box_coding as mailCoding from oa_mail where ISSUANCE_ID =:userId group by Mail_box_coding";
SQLQuery sqlQuery = (SQLQuery) super.getSession().createSQLQuery(sql).setString("userId",userId);
List<Object[]> students = sqlQuery.list();
for (Iterator<Object[]> iterator = students.iterator(); iterator.hasNext();) {
Object[] mailInfo = iterator.next();
logger.info("查詢出的結果mailInfo mailCount"+mailInfo[0]+"mailCoding"+mailInfo[1]);
mailSizeInfo.put(mailInfo[1],mailInfo[0]);
}
}catch(Exception ex){
ex.printStackTrace();
throw new PageJumpException();
}
將查詢結果放入到map中
到業務邏輯處理中將map中的值取出來,並組裝成需要的數據格式
String record="";
Iterator it = mailSizeInfo.entrySet().iterator();
while (it.hasNext()){
Map.Entry pairs = (Map.Entry)it.next();
logger.info(pairs.getKey() + " = " + pairs.getValue());
String recordNode=pairs.getKey()+":'" +pairs.getValue()+"'";
if (record.length() == 0) {
record = recordNode;
} else {
record = record + "," + recordNode;
}
}
String recordsJson = "{"+record + "}";
Iterator it = mailSizeInfo.entrySet().iterator();
while (it.hasNext()){
Map.Entry pairs = (Map.Entry)it.next();
logger.info(pairs.getKey() + " = " + pairs.getValue());
String recordNode=pairs.getKey()+":'" +pairs.getValue()+"'";
if (record.length() == 0) {
record = recordNode;
} else {
record = record + "," + recordNode;
}
}
String recordsJson = "{"+record + "}";