0

我使用 mysql 存储过程来检索对象列表。这可能吗 ?

我在关注这篇文章

问题:

  1. 如何使用结果集在 select 语句中检索对象列表?
  2. 如何将结果集映射到对象列表?

    CREATE DEFINER= root@ localhostPROCEDURE generateLCRReport(IN countryCodeParamINT, OUT countryCodeINT, OUT dialCodeINT, OUT custPrefixVARCHAR(50), OUT vendorPrefixVARCHAR(50), OUT custPriceFLOAT, OUT vendorCostFLOAT, OUT profitFLOAT) 语言 SQL 确定性读取 SQL 数据 SQL 安全定义器注释“generateLCRReport”开始选择 c.country_code 作为 countryCode,c.dial_code 作为 dialCode,c.customer_prefix 作为 custPrefix,c.vendor_prefix 作为 vendorPrefix,max(cust_rate.rate) 作为 custPrice,min(ven_rate.rate) 作为 vendorCost,round(max(cust_rate.rate) ) - min(ven_rate.rate), 3) 作为 cdr c 的利润

    inner join (select a.id, r.rate, re.country_code, re.dial_code, ap.prefix from rate r inner join region re on r.region_id = re.id inner join account_prefix ap on r.account_prefix_id = ap.id a.id = ap.account_id 上的内部加入帐户 a,其中 ap.prefix_type = 0 )作为 cust_rate

    在 c.country_code = cust_rate.country_code 和 c.dial_code = cust_rate.dial_code 和 c.customer_prefix = cust_rate.prefix 和 c.customer_id = cust_rate.id

    inner join (select a.id, r.rate, re.country_code, re.dial_code, ap.prefix from rate r inner join region re on r.region_id = re.id inner join account_prefix ap on r.account_prefix_id = ap.id内部加入帐户 a on a.id = ap.account_id where ap.prefix_type = 1 ) as ven_rate

    在 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.dial_code 顺序由 c .country_code 升序限制 5000;

    结尾

    公共类 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);
    }
    

    }

请帮忙。

谢谢。

4

1 回答 1

0

我正在使用 RowMapper 并声明参数 SqlReturnResultSet。

于 2013-03-13T04:05:05.063 回答