2011-07-18 17 views
0

私はibatisで継承マッピングを持つ必要があります。上記resultmapのこのIbatisのselectステートメントの列の値に基づく動的クエリ?

<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> 

をサブマップは、別のオブジェクトに列をマップし、次のように同じようiBATISのドキュメントでは、何であるか私が学んできた、我々はこのresultMapの弁別タグ内のサブマップを呼び出すには、列の値を比較することができます。

しかし、私は必要な列を得ることができるようにselect文自体のcolumnの値を比較したいと思います。次のようなものがあります。

<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でも可能ですか?

あなたは私の問題を理解していることを願っています。質問が明確でない場合は、これを再編集して喜んで解説します。

ありがとうございます。

答えて

2

あなたは次のように試みることができますか?

<select id="load" resultMap="map"> 
    select mt.id,mt.name, mt.type 
    <if type = "1"> 
     table1.column1, table1.column2 ... table1.columnN 
    </if> 
    <if type = "2"> 
     table2.column1, table2.column2 ... table2.columnN 
    </if> 
    from main_table mt 
    <if type = "1"> 
     LEFT OUTER JOIN TABLE1 table1 ON mt.id=table1 
    </if> 
    <if type = "2"> 
     LEFT OUTER JOIN TABLE2 table2 ON mt.id=table2 
    </if> 
    where mt.id=#{value} 
</select> 

あなたは以上のように、いくつかのエラーに直面した場合...

を返信してください
関連する問題