天天看點

mybatis中調用遊标,存儲過程,函數

    在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

轉載:https://www.cnblogs.com/xushirong/p/6999568.html   存儲過程,和函數

mybatis中調用遊标,存儲過程,函數