jdbcTemplate的queryForList的使用方法

jdbcTemplate的queryForList的使用方法如下,它不一样的地方是,它获得的结果,会再放到一个map里去:

List rows = jdbcTemplate.queryForList("SELECT * FROM USER");
  Iterator it = rows.iterator();  
 while(it.hasNext()) {     
  Map userMap = (Map) it.next();     
  System.out.print(userMap.get("user_id") + "\t");     
  System.out.print(userMap.get("name") + "\t");    
   System.out.print(userMap.get("sex") + "\t");     
  System.out.println(userMap.get("age") + "\t");   } 

StringBuffer buffer = new StringBuffer();
buffer.append("SELECT ")
.append(" w.WZ_INCODE,r.ACTIVITY_ID,w.WZ_NAME,w.SALE_PRICE,w.MARKET_PRICE,r.ACT_NUM,r.ACT_PRICE,r.LIMIT_NUM,r.NOW_NUM,r.ORDER_NUM,")
.append(" CONCAT('/',(SELECT f.pic_idx FROM file_path_conf f WHERE f.incode = 410),IFNULL(w.ICON, '')) AS GOODS_ICON FROM");
buffer.append(" wz_code w left join store_activity_goods_rel r on r.WZ_INCODE = w.WZ_INCODE ");
if("0".equals(isRightControl)){
buffer.append(" LEFT JOIN wz_code_company_rel o on w.WZ_INCODE = o.WZ_INCODE ");
}
buffer.append(" where 1=1 ");
if("0".equals(isRightControl)){
buffer.append(" and (w.COMPANY_ID in ( " );
for (int i = 0; i < userCompanyId.length; i++) {
buffer.append(userCompanyId[i]);
if (i != userCompanyId.length - 1) {
buffer.append(",");
}
}
buffer.append(") or o.COMPANY_ID=0 )");
}
//根据工会id查询出场次
//select SELECT ul.LOGIN_ID FROM hr_employee he, ep_r_user_login ul WHERE ul.PARTY_ID = he.PARTY_ID and COMPANY_ID=2241
buffer.append(" and r.WZ_INCODE = w.WZ_INCODE AND w.PASS_MARK = 'Y' AND ifnull(r.up_incode, 0) <= 0 AND w.USE_MARK = 'Y' AND w.UP_DOWN_FLAG = 3 and r.STATUS_FLAG='Y' ")
.append(" and NOW_NUM>0 AND r.ACTIVITY_ID = ? and r.SESSION_ID =? and r.CREATE_OPER in( SELECT ul.LOGIN_ID FROM hr_employee he, ep_r_user_login ul WHERE ul.PARTY_ID = he.PARTY_ID and COMPANY_ID=?) ")
.append(" ORDER BY r.NOW_NUM ASC LIMIT ?,?");
Object[] args = {activityId,sessionId,userCompanyId[0],startString,endString};
int[] argTypes = {Types.VARCHAR,Types.VARCHAR,Types.DECIMAL,Types.NUMERIC,Types.NUMERIC};
List<HashMap> list = GlobFunc.keyUpCaseToLowForListOrderMap(jdbcTemplate.queryForList(buffer.toString(),args,argTypes));
return list;

posted @ 2017-12-25 20:33  逆水乘舟,不进则退  阅读(12881)  评论(0编辑  收藏  举报