我有以下结构的实体:
id: 123,
key1: bla1
properties: {
key2: bla2
}
我需要从DB中选择这样的实体并将其映射到:
id: 123,
properties: {
key1: bla1
key2: bla2
}
无论是在SELECT级别还是在resultMap(MyBatis)级别上都无关紧要。
答案 0 :(得分:2)
所以SQL是:
SELECT t1.id, t1.key1, p.key2 FROM t1 JOIN properties p ON [join clause]
结果图:
<resultMap id="rm">
<id column="id", property="id">
<association property="properties" type="">
<result column="key1" property="key1" />
<result column="key2" property="key2" />
</association>
</resultMap>
虽然第一个实体映射的结果映射如下所示,但列/属性在主对象中,不关联:
<resultMap id="rm">
<id column="id", property="id">
<result column="key1" property="key1" />
<association property="properties" type="">
<result column="key2" property="key2" />
</association>
</resultMap>