周翔 发表于 2016-11-27 10:41:50

MyBatis调用存储过程返回多结果集(转)


[*]圈首页
[*]分享
[*]成员






MyBatis调用存储过程返回多结果集

Java开发>分享>Java框架


http://www.liutime.com/avatar/92.jpg
賤男春圈子贡献 | Ta的空间



  数据库用的是SqlServer2008
  图片为数据库执行存储过程返回的数据
http://www.liutime.com/img/234.jpg
  Mybatis调用存储过程返回结果集
  配置文件

<resultMap type="Integer" id="count">
<result column="RecordCount"   jdbcType="INTEGER" javaType="Integer" />   
</resultMap>
<resultMap type="OrderForm" id="orders">   
<result column="OrderId" property="id" jdbcType="VARCHAR" javaType="String"/>
</resultMap>
<select id="getOrders" statementType="CALLABLE" parameterType="Map"resultMap="count,orders" >
{call Page_Up_Get_OrderState(#{id,mode=IN,jdbcType=VARCHAR})}
</select>

  需要注意的地方 statementType="CALLABLE" 不能少resultMap="count,orders" 这里返回多个结果集,如果有更多可以继续加
  Dao层的接口

public List<List<?>>getOrders(Map<String, Object> map);

  Service层调用

   Map<String,Object> map=new HashMap<String, Object>();
map.put("id", "22333");
//取得返回的结果集   
List<List<?>> results = orderDao.getOrders(map);
//第一条结果集 总数量
System.out.println(((List<Integer>)results.get(0)).get(0));
//第二条订单列表
System.out.println((List<OrderForm>)results.get(1));
页: [1]
查看完整版本: MyBatis调用存储过程返回多结果集(转)