Recently, a development has raised a demand, I hope that the middleware support call MySQL stored procedures to support multi-result set return, because for some reason we use a lot of stored procedures, many complex logic at present the interaction is very much, so from the current situation, the demand is quite reasonable. At noon, the time for a special search, the integration of the complete example is as follows:
1. Create a test stored procedure
delimiter $$CREATE PROCEDURESp_multi_resultset (inchP_operator_company_noint, inchP_operator_noint, out P_error_codevarchar( +), out P_error_infovarchar(255))BEGIN Select 1 asCol1,2 ascol2;Select One asCOL11, A ascol21;End$ $delimiter; call Sp_multi_resultset (1,1,@error_code,@error_info);
2. Mapper File
<?XML version= "1.0" encoding= "UTF-8"?> <!DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd "> <Mappernamespace= "Multiresultset"> <Resultmaptype= "Test. Test "ID= "Test1"> <resultcolumn= "Col1"Jdbctype= "INTEGER"Javatype= "Integer" /> <resultcolumn= "Col2"Jdbctype= "INTEGER"Javatype= "Integer" /> </Resultmap> <Resultmaptype= "Test. Test2 "ID= "Test2"> <resultcolumn= "Col1"Jdbctype= "INTEGER"Javatype= "Integer" /> <resultcolumn= "Col3"Jdbctype= "INTEGER"Javatype= "Integer" /> </Resultmap> <SelectID= "Gettests"StatementType= "callable"ParameterType= "Map"Resultmap= "Test1,test2" >{call Sp_multi_resultset (#{param1,mode=in,jdbctype=integer},#{param2,mode=in,jdbctype=integer},#{errorcode, Mode=out,jdbctype=varchar},#{errorinfo,mode=out,jdbctype=varchar})}</Select></Mapper>
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 code
/** * */ 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;/** * @author[email protected] * {@link} http://www.cnblogs.com/zhjh256 */@Service Public classTestmultiresultsetImplementsInitializingbean {@AutowiredPrivatesqlsessiontemplate sqlsession; /*(non-javadoc) * @see org.springframework.beans.factory.initializingbean#afterpropertiesset ()*/@Override Public voidAfterpropertiesset ()throwsException {Map<String,String> map =NewHashmap<string,string>(); Map.put ("Param1", "1"); Map.put ("Param2", "1"); Map.put ("ErrorCode", "" "); Map.put ("ErrorInfo", "" "); List<List<?>> Multiresult = sqlsession.selectlist ("multiresultset.gettests", map); System.out.println (Jsonutils.tojson (Multiresult.get (0))); System.out.println (Jsonutils.tojson (Multiresult.get (1))); }}
Output:
[NULL]
[NULL]
The explanation didn't come back ... This on-line all come out, in the end is measured not test it .... Difficult is spring-mybatis to castration, with the native mybatis look.
MyBatis calling a MySQL stored procedure returns a multi-result set (full)