http://xiangai.taobao.com
http://shop148612228.taobao.com

mybatis中用注解如何处理存储过程返回的多个结果集?

sql代码:

Sql代码  收藏代码
  1. create procedure sptest.getnamesanditems()  
  2. reads sql data  
  3. dynamic result sets 2  
  4. BEGIN ATOMIC  
  5.   declare cur1 cursor for select * from sptest.names;  
  6.   declare cur2 cursor for select * from sptest.items;  
  7.   open cur1;  
  8.   open cur2;  
  9. END  
  10. go  




Xml代码  收藏代码
  1. <resultMap type="org.apache.ibatis.submitted.sptests.Name" id="nameResult">  
  2.     <result column="ID" property="id"/>  
  3.     <result column="FIRST_NAME" property="firstName"/>  
  4.     <result column="LAST_NAME" property="lastName"/>  
  5.   </resultMap>  
  6.   
  7.   <resultMap type="org.apache.ibatis.submitted.sptests.Item" id="itemResult">  
  8.     <result column="ID" property="id"/>  
  9.     <result column="ITEM" property="item"/>  
  10.   </resultMap>  
  11.   
  12.   <select id="getNamesAndItems" statementType="CALLABLE"  
  13.     resultMap="nameResult,itemResult">  
  14.     {call sptest.getnamesanditems()}  
  15.   </select>  



Java代码  收藏代码
    1. @Test  
    2.     public void testGetNamesAndItems() throws SQLException {  
    3.         SqlSession sqlSession = sqlSessionFactory.openSession();  
    4.         try {  
    5.             SPMapper spMapper = sqlSession.getMapper(SPMapper.class);  
    6.               
    7.             List<List<?>> results = spMapper.getNamesAndItems();  
    8.             assertEquals(2, results.size());  
    9.             assertEquals(4, results.get(0).size());  
    10.             assertEquals(3, results.get(1).size());  
    11.         } finally {  
    12.             sqlSession.close();  
    13.         }  
    14.     }  

 

原文地址:https://www.iteye.com/problems/78259

posted @ 2019-08-15 20:05  万事俱备就差个程序员  阅读(403)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏