具有多列的 Mybatis 集合

Mybatis collection with multiple columns

我有一个 table,它有三个项目的外键。这些对应的对象我要在一个列表中属性。我有以下集合映射

<collection property="items" column="{item1Id, item2Id, item3Id}">
    <association property="exampleNestedItem" column="{id, ###itemId###}" select="com.example.mapper.getItem" />
</collection>

我需要###itemId### 的当前值。如何为该参数引用 "item1Id"、"item2Id" 和 "item3Id" 列?

我最终找到了一个非常简单的解决方案。就我而言,我知道该列表中总会有 3 个元素。所以我为模型中的每个元素添加了一个 setter class 像这样

public void setElement1(Element element) {
   elements.add(element);
}
...

并且我为每个元素添加了一个关联

<association property="element1" column="element1Id" select="com.example.mapper.getItemWithId"/>    
...

它肯定不会针对许多元素进行缩放,但对于我的情况来说它适合!