【发布时间】:2011-07-18 07:18:01
【问题描述】:
我需要在 ibatis 中有继承映射。在Ibatis文档中,我学到的是,我们可以比较列的值来调用resultMap的discriminator标签内的子图,如下所示:
<resultMap id="map">
<discriminator javaType="java.lang.Integer" column="type">
<subMap resultMap="submap1" value="1" />
<subMap resultMap="submap2" value="2"/>
<subMap resultMap="submap3" value="3"/>
</discriminator>
</resultMap>
在上面的结果图中,子图将列映射到不同的对象。
但我想比较 select 语句本身中列的值,以便获得所需的列。一些类似如下:
<select id="load" resultMap="map">
select mt.id,mt.name, mt.type
<here we have to check the value of type column returned dynamically>
<if type = "1">
table1.column1, table1.column2 ... table1.columnN
</if>
<if type = "2">
table2.column1, table2.column2 ... table2.columnN
</if>
</here>
from main_table mt
LEFT OUTER JOIN TABLE1 table1 ON mt.id=table1
LEFT OUTER JOIN TABLE2 table2 ON mt.id=table2
where mt.id=#value#
</select>
这只是满足我要求的算法。在 Ibatis 中可以吗?
希望你能理解我的问题。如果问题不清楚,我很乐意重新编辑以使您清楚。
提前致谢。
【问题讨论】: