我使用mysql存儲過程用來檢索對象列表。這可能嗎 ?Spring StoredProcedure對象對象返回列表
我下面這個article
問:
- 如何使用結果集檢索對象的名單就像在SELECT語句?
如何將結果集映射到對象列表?
CREATE DEFINER =
root
@localhost
PROCEDUREgenerateLCRReport
(INcountryCodeParam
INT,OUTcountryCode
INT,OUTdialCode
INT,OUTcustPrefix
VARCHAR(50),OUTvendorPrefix
VARCHAR(50),OUTcustPrice
FLOAT,OUTvendorCost
FLOAT,OUTprofit
FLOAT ) LANGUAGE SQL DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER COMMENT 'generateLCRReport' BEGIN 選擇c.country_code如COUNTRYCODE,c.dial_code如dialCode, c.customer_prefix如custPrefix ,c.vendor_prefix as vendorPrefix, max(cust_rate.rate)as custPrice,min(ven_rate.rate)as vendorCost, round(max(cust_rate.rate) - min(ven_rate.rate),3)來自cdr的利潤 ç內加入 (選擇a.id,r.rate,re.country_code,re.dial_code,ap.prefix從速率r 內部聯接區域重新上r.region_id = re.id 內部聯接account_prefix AP上r.account_prefix_id = ap.id 內連接上a.id = ap.account_id 帳戶a其中ap.prefix_type = 0 )作爲c.country_code cust_rate
= cust_rate.country_code 和c.dial_code = cust_rate.dial_code 和c.customer_prefix = cust_rate.prefix 和c.customer_id = cust_rate.id
內加入 (選擇a.id,r.rate,重。國內代碼,re.dial_code,來自費率r的ap.prefix 內部加入區域re on r.region_id = re.id 內部加入account_prefix ap上r.account_prefix_id = ap.id 內部加入帳戶a上a.id = ap。 account_id where ap.prefix_type = 1 )as ven_rate
on c.country_code = ven_rate.country_code 和c.dial_code = ven_rate.dial_code 和c.vendor_prefix = ven_rate.prefix 和c.vendor_id = ven_rate.id 其中c.country_code = countryCodeParam 組由c.country_code和被C c.dial_code 順序。country_code asc limit 5000;
END
公共類LCRReportSP擴展StoredProcedure的{
/** * */ @Autowired public LCRReportSP(JdbcTemplate jdbcTemplate, String storedProcName, RowMapper<CostReport> mapper) { super(jdbcTemplate, storedProcName); SqlReturnResultSet rs = new SqlReturnResultSet("", mapper); SqlOutParameter outParam = new SqlOutParameter("countryCode", Types.INTEGER); SqlOutParameter outParam1 = new SqlOutParameter("dialCode", Types.INTEGER); SqlOutParameter outParam2 = new SqlOutParameter("custPrefix", Types.VARCHAR); SqlOutParameter outParam3 = new SqlOutParameter("vendorPrefix", Types.VARCHAR); SqlOutParameter outParam4 = new SqlOutParameter("custPrice", Types.FLOAT); SqlOutParameter outParam5 = new SqlOutParameter("vendorCost", Types.FLOAT); SqlOutParameter outParam6 = new SqlOutParameter("profit", Types.FLOAT); this.declareParameter(rs); this.declareParameter(outParam); this.declareParameter(outParam1); this.declareParameter(outParam2); this.declareParameter(outParam3); this.declareParameter(outParam4); this.declareParameter(outParam5); this.declareParameter(outParam6); this.setFunction(false); this.compile(); } /** * @param countryCode * @return */ public Map<String, ?> generateLCRReport(int countryCode) { Map<String, Object> inParam = new HashMap<String, Object>(); inParam.put("countryCodeParam", new Integer(countryCode)); return this.execute(inParam); }
}
請幫助。
謝謝。
你可以試試'resultSetExtractor' – Anubhab 2013-03-12 10:29:06