zoukankan      html  css  js  c++  java
  • Mybatis下配置调用Oracle自定义函数返回的游标结果集

            在ibatis和Mybatis对存储过程和函数函数的调用的配置Xml是不一样的,以下是针对Mybatis 3.2的环境进行操作的。

    •    第一步配置Mapper的xml内容
    <mapper namespace="com.rrtong.rrt.auto.dao.SelfStatisticDataDao">
     	<resultMap id="SelfStatisticData" type="SelfStatisticData">  
            <id 	column="name" 	property="name" />  
            <result column="count" 	property="count"/>        
        </resultMap>
    	
    	<select id="getSelfStatisticData" parameterType="HashMap" statementType="CALLABLE" >
     	    {#{result,mode=OUT,jdbcType=CURSOR, resultMap=SelfStatisticData} = call PKG_RRT_SelfStatics.Fn_GetSelfStatData(#{userCode,jdbcType=VARCHAR,mode=IN})	}    	
    	</select> 	
    </mapper>

                   说明:

                               1、result对应的是oracle自定义函数返回的游标

                               2、映射对象resultMap对应的是SelfStaticData

                               3、userCode为传入参数

    • 在Service层中如何得到该游标的数据集呢?下面为调用实例,
    @Service
    public class SelfStatisticDataServiceImpl implements SelfStatisticDataService{
    	@Resource
    	SelfStatisticDataCache selfStatisticDataCache;
    	
    	public List<?> getSelfStatisticData(String userCode){		
    		List<?> selfStaticDataList = new ArrayList<Map<String,Object>>();
    		HashMap<String,Object> statMap = new HashMap<String,Object>();
    		statMap.put("userCode", userCode);
                    /*设定游标结果写入的变量*/
                    statMap.put("result", selfStaticDataList);	
    		
    		selfStatisticDataCache.getSelfStatisticData(statMap);
    		/*获取返回的游标结果集*/
                    selfStaticDataList = (List<?>) statMap.get("result");	
    
    		return selfStaticDataList;
    	}
    }
    




  • 相关阅读:
    C加加学习之路 1——开始
    哈夫曼树C++实现详解
    Linux常用命令
    Accp第二章:基础知识
    第一章Accp 8.0
    泛型集合
    深入C#数据类型
    初始wondows系统
    深入.NET框架
    二至十五章总结
  • 原文地址:https://www.cnblogs.com/wala-wo/p/5119236.html
Copyright © 2011-2022 走看看