結論: 通過設置別名的方式讓其產生區別
<select id="queryBySekillId" resultMap="successKilled">
select
sk.seckill_id "seckill_id",
sk.user_phone "user_phone",
sk.state "state",
sk.create_time "create_time",
s.seckill_id "seckill_id",
s.name "name",
s.number "number",
s.start_time "start_time",
s.end_time "end_time",
s.create_time "screate_time"
from success_killed sk
inner join seckill s
on sk.seckill_id = s.seckill_id
where sk.seckill_id = #{seckill_id} ;
</select>
以上 success_killed表和seckill表中有相同字段 create_time (id字段其實確實是相同的故在此忽略),通過將表seckill的create_time字段命名為screate_time用以區別。
<resultMap type="Seckill" id="seckill"> <id column="seckill_id" property="seckill_id"/> <result column="name" property="name"/> <result column="number" property="number"/> <result column="start_time" property="start_time" /> <result column="end_time" property="end_time"/> <result column="screate_time" property="create_time" /> </resultMap>
同時將 resultMap中該段的 column 屬性該為 screate_time.故只要讓查詢出的字段名與column相同,它會通過映射找到相應屬性進行封裝。
