我使用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