简要问题描述
遵循多个结果集的指南并在此答案的帮助下,我现在能够提取 2 个不同的记录集,但它们只是列表,并没有映射到结果对象上。
详细介绍
我有课程(简化):
public class SupplyChain{
private String id;
private List<SupplyChainNode> nodes;
private List<SupplyChainEdge> edges;
}
public class SupplyChainNode {
private String id;
private String label;
}
public class SupplyChainEdge {
private String id;
private String label;
}
MyBatis
接口声明如下:
public interface SupplyChainMBDao {
List<SupplyChain> getByPartyId(@Param("partyId") String partyId);
}
和MyBatis
映射:
<mapper namespace="ru.rlh.egais.portal.backend.dao.mybatis.SupplyChainMBDao">
<select id="getByPartyId" resultSets="edges,nodes" resultMap="supplyChainMapEdge, supplyChainMapNode"><![CDATA[
-- There big query returns 2 recordset - first for Edges and second for Nodes. They have different amount of rows and logic of obtain, but share initial computation and it is desire to return them atomic.
-- Let it be for simplicity:
SELECT * FROM (VALUES(1, 2)) edges(id, label);
SELECT * FROM (VALUES(2, 3), (4, 5)) nodes(id, label)
]]></select>
<resultMap id="supplyChainMapEdge" type="ru.rlh.egais.portal.api.dto.bo.supplychain.SupplyChainEdge" >
<result property="label" column="label"/>
</resultMap>
<resultMap id="supplyChainMapNode" type="ru.rlh.egais.portal.api.dto.bo.supplychain.SupplyChainNode" >
<result property="label" column="label"/>
</resultMap>
</mapper>
所以,基本上它可以工作,我得到了 2 个集合。List<SupplyChain>
但是,我真正得到了List<List>
内部列表在运行时包含 2 个元素的位置,而不是声明的返回值:
- 0 元素是
List<SupplyChainEdge>
- 第一个:
List<SupplyChainNode>
。
如何将这些原始集合包装到对象中SupplyChain
?