zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    }
  • 相关阅读:
    14.使用nodejs将规定格式的txt转化为json数据
    13.resize妙用(书上看到的)
    12.写了一个怪怪的边框
    11.一起来抄一个小小的提示菜单
    UI02-textfiled.按钮 uibutton
    UI01-UIview UIlable的属性
    OC9-内存管理
    OC8-属性 KVC是键值编码
    OC7-‍ 类目,延展 协议代理。
    OC6-block-函数指针
  • 原文地址:https://www.cnblogs.com/wangyang108/p/6007069.html
Copyright © 2011-2022 走看看