2012-06-12 102 views
2

如何忽略iBatis resultMap上的缺失列?忽略缺失列

如果我有这样的映射

<resultMap id="DBEntity" class="CS_Entity"> 
    <result property="Id" column="Id" /> 
    <result property="Field1" column="f1" /> 
    <result property="Field2" column="f2" /> 
</resultMap> 

某些查询我想要回塔F2,但我怎么能不声明使用默认值将所有其他查询字段F2。

有没有办法?

回答

1

使用两resultsMap一个与f2

<resultMap id="DBEntityWithF2" class="CS_Entity"> 
    <result property="Id" column="Id" /> 
    <result property="Field1" column="f1" /> 
    <result property="Field2" column="f2" /> 
</resultMap> 

和另一个不f2

<resultMap id="DBEntity" class="CS_Entity"> 
    <result property="Id" column="Id" /> 
    <result property="Field1" column="f1" /> 
</resultMap> 
1

您可以在SQL只需使用"select f2 as Field2 from yourTable",并使用resultClass="CS_Entity",而不是在你的配置中使用resultMap。这样,你不需要像上面那样声明映射。