Ibatis的select语句根据列值进行动态查询?
我需要在 ibatis 中进行继承映射。在Ibatis文档中,我了解到,我们可以比较列的值来调用resultMap的鉴别器标记内的子图,如下所示:
<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中可以吗?
希望你理解我的问题。如果问题不清楚,我很乐意重新编辑它以使您清楚。
提前致谢。
I need to have inheritance mapping in ibatis. In Ibatis documentation, what I have learned is, we can compare the value of the column to call submaps inside discriminator tag of resultMap like as follows:
<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>
In the above resultmap, the submaps maps the columns to different object.
But I want to compare the value of column in select statement itself so that I can get the required columns. some what like as follows:
<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>
This is just an algorithm for my requirement. Is it possible in Ibatis?
Hope you understand my problem. If the question is not clear, I am happy to reedit this to make you clear.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试以下方式吗?
如果您在上述方式中遇到一些错误,请回复...
You could try in following way?
If you face some error in above way please reply...