在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 存儲過程,和函數