最近,有个开发提了个需求,希望中间件支持调用mysql存储过程时支持多结果集返回,因为某些原因我们使用了不少的存储过程,很多复杂的逻辑目前来看交互非常的多,所以从当前的现状来说,这个需求还是蛮合理的。中午抽空特地搜了下,整合完整示例如下:
1、创建测试存储过程
delimiter $$CREATE PROCEDURE sp_multi_resultset(IN p_operator_company_no int,IN p_operator_no int,
OUT p_error_codevarchar(32),
OUT p_error_infovarchar(255))BEGIN
select 1 as col1,2 ascol2;select 11 as col11,22 ascol21;end$$
delimiter ;
call sp_multi_resultset(1,1,@error_code,@error_info);
2、mapper文件
/p>
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
{call sp_multi_resultset(#{param1,mode=IN,jdbcType=INTEGER},#{param2,mode=IN,jdbcType=INTEGER},#{errorCode,mode=OUT,jdbcType=VARCHAR},#{errorInfo,mode=OUT,jdbcType=VARCHAR})}
https://github.com/mybatis/mybatis-3/issues/132
http://mybatis-user.963551.n3.nabble.com/Multiple-result-set-with-MyBatis-td2730801.html
http://bbs.csdn.net/topics/391003384
3、java代码
/****/
packagecom.medsoft.top10.dao;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importorg.mybatis.spring.SqlSessionTemplate;importorg.springframework.beans.factory.InitializingBean;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importcom.cyl.kernel.util.JsonUtils;/***@authorzhjh256@163.com
* {@link}http://www.cnblogs.com/zhjh256
*/@Servicepublic class TestMultiResultSet implementsInitializingBean {
@AutowiredprivateSqlSessionTemplate sqlSession;/*(non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()*/@Overridepublic void afterPropertiesSet() throwsException {
Map map = new HashMap();
map.put("param1", "1");
map.put("param2", "1");
map.put("errorCode", "");
map.put("errorInfo", "");
List> multiResult = sqlSession.selectList("MultiResultset.getTests",map);
System.out.println(JsonUtils.toJson(multiResult.get(0)));
System.out.println(JsonUtils.toJson(multiResult.get(1)));
}
}
输出:
[null]
[null]
说明压根没返回啊。。。这网上一个个都出来的,到底是测没测试呢。。。。难不成是spring-mybatis给阉割了,用原生mybatis看看。