0
這是MyBatis的XML配置的一部分。取決於列值的不同集合
<sql id="selectElementWithAttributes">
SELECT
e.id as id,
e.title as title,
e.type as type,
e.date as date,
e.ownerid as ownerid,
a.attributeid as attributeid,
a.value as value,
a.type as a_type
FROM
test_element as a
LEFT JOIN
test_elementattributes as a
ON
e.id
= a.parentid
</sql>
現在我使用resultMap將列映射到我的對象。
<resultMap type="Element" id="rmElement">
<id property="id" column="id" />
<result property="title" column="title" />
<result property="type" column="type" />
<result property="date" column="date" />
<result property="ownerid" column="ownerid" />
<collection property="attributes" ofType="Attribute">
<id property="{id=parentid,attributeid=attributeid}" />
<result property="key" column="attributeid" />
<result property="value" column="value" />
</collection>
</resultMap>
問題是,我有我的元素對象的集合。 這兩個集合都包含屬性。 不同之處在於屬性的類型(映射到a_type)。 取決於這種類型,我喜歡在集合1或集合2中具有屬性。 我用鑑別器玩弄,但並不真正瞭解我在做什麼,它不工作...
This是這個想法,但是如何根據a_type切換集合?
<resultMap type="Element" id="rmElement">
<id property="id" column="id" />
<result property="title" column="title" />
<result property="type" column="type" />
<result property="date" column="date" />
<result property="ownerid" column="ownerid" />
<collection property="attributes" ofType="Attribute">
<id property="{id=parentid,attributeid=attributeid}" />
<result property="key" column="attributeid" />
<result property="value" column="value" />
</collection>
<collection property="attributesOther" ofType="Attribute">
<id property="{id=parentid,attributeid=attributeid}" />
<result property="key" column="attributeid" />
<result property="value" column="value" />
</collection>
</resultMap>
在此先感謝
完美的作品。我需要處理這兩個集合,但速度夠快。非常感謝 – Nabor