MyBatis的:先进结果马平
问题描述:
我有实体结构如下:MyBatis的:先进结果马平
id: 123,
key1: bla1
properties: {
key2: bla2
}
我需要从数据库中选择这样的实体,并将其映射到:
id: 123,
properties: {
key1: bla1
key2: bla2
}
不要紧,如果是在SELECT级别或在resultMap(MyBatis)级别。
感谢您的任何建议!
答
所以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>