0 0

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

mybatis中用注解如何处理存储过程返回的多个结果集?我调用一个存储过程,但这个存储过程里又调用多个存储过程,所以会返回多个有多条记录的多个结果集?用mybatis如何得到这些结果集呢?用注解如何得到,如果注解不能处理?其它方式如何处理?谢谢!
2012年1月18日 11:22

1个答案 按时间排序 按投票排序

0 0

用xml 配置文件吧


给个列子 你就懂了
sql代码:

create procedure sptest.getnamesanditems()
reads sql data
dynamic result sets 2
BEGIN ATOMIC
  declare cur1 cursor for select * from sptest.names;
  declare cur2 cursor for select * from sptest.items;
  open cur1;
  open cur2;
END
go



<resultMap type="org.apache.ibatis.submitted.sptests.Name" id="nameResult">
    <result column="ID" property="id"/>
    <result column="FIRST_NAME" property="firstName"/>
    <result column="LAST_NAME" property="lastName"/>
  </resultMap>

  <resultMap type="org.apache.ibatis.submitted.sptests.Item" id="itemResult">
    <result column="ID" property="id"/>
    <result column="ITEM" property="item"/>
  </resultMap>

  <select id="getNamesAndItems" statementType="CALLABLE"
    resultMap="nameResult,itemResult">
    {call sptest.getnamesanditems()}
  </select>


@Test
    public void testGetNamesAndItems() throws SQLException {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
            
            List<List<?>> results = spMapper.getNamesAndItems();
            assertEquals(2, results.size());
            assertEquals(4, results.get(0).size());
            assertEquals(3, results.get(1).size());
        } finally {
            sqlSession.close();
        }
    }

2012年9月03日 00:28

相关推荐

Global site tag (gtag.js) - Google Analytics