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;
	}
}




原文地址:https://www.cnblogs.com/wala-wo/p/5119236.html