mybatis中用注解如何处理存储过程返回的多个结果集?
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();
- }
- }
原文地址:https://www.iteye.com/problems/78259