spring jdbctemplate调用procedure(返回游标)
package cn.com.git.htsc.uac.core.repository.report; import cn.com.git.htsc.uac.core.api.dto.report.ReportCampaignDayOutDTO; import oracle.jdbc.OracleTypes; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcCall; import org.springframework.stereotype.Repository; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; /** * Created by wangyang on 2016/10/28. */ @Repository public class ReportCampaignTotalRepository { @Autowired private JdbcTemplate primaryJdbcTemplate; public List<ReportCampaignDayOutDTO> getCampaignTotal(String start_date,String end_date,String campId,String deptId,String statu){ SimpleJdbcCall jdbcCall = new SimpleJdbcCall(primaryJdbcTemplate).withProcedureName("pro_credit_total").declareParameters( new SqlOutParameter("results_out", OracleTypes.CURSOR, new QueryExchangeOrderDTOTypeMapper()) ); MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(); mapSqlParameterSource.addValue("startd", start_date); mapSqlParameterSource.addValue("endd", end_date); mapSqlParameterSource.addValue("actiid", campId); mapSqlParameterSource.addValue("deptid", deptId); mapSqlParameterSource.addValue("stat", statu); Map<String, Object> results = jdbcCall.execute(mapSqlParameterSource); List<ReportCampaignDayOutDTO> results_out = (List<ReportCampaignDayOutDTO>) results.get("results_out"); return results_out; } private class QueryExchangeOrderDTOTypeMapper implements RowMapper { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { ReportCampaignDayOutDTO dayOutDTO=new ReportCampaignDayOutDTO(); dayOutDTO.setCampaignId(rs.getString("campaign_id")); dayOutDTO.setDayJoinPersonNum(rs.getLong("day_join_person_num")); dayOutDTO.setDayJoinCountNum(rs.getLong("day_join_count_num")); dayOutDTO.setDayCreditEarnNum(rs.getLong("day_credit_earn_num")); dayOutDTO.setDayCreditExpendNum(rs.getLong("day_credit_expend_num")); return dayOutDTO; } } }