今天从mybatis迁移一个mapper到ibatis(2.0)中,发现有一个标签(association),ibatis不支持。
mybatis中的代码:
JavaBean
@Data public class InstitutionExpert extends BaseBusEntity { private String id;private String createBy;private Date createDate;private String updateBy; private Date updateDate; private Integer deleteFlag; private Expert expert;}
mapper.xml:简写
<resultMap type="institutionExpert" id="institutionExpertResultMap"> <id property="id" column="ID" /> <result property="createBy" column="C_CREATE_BY" /> <result property="createDate" column="C_CREATE_DATE" /> <result property="updateBy" column="C_UPDATE_BY" /> <result property="updateDate" column="C_UPDATE_DATE" /> <result property="deleteFlag" column="C_DELETE_FLAG" /> <association property="expert" javaType="expert" column="C_EXPERT_ID"> <id property="id" column="C_EXPERT_ID" /> </association></resultMap<select id="listInstitutionExpertByPage" resultMap="institutionExpertResultMap"> SELECT <include refid="allColumnSql"/> FROM institution_expert o left join expert e on o.C_EXPERT_ID = e.ID WHERE o.C_EXPERT_ID is NOT null <include refid="searchConditionSql"/> </select>
由于ibatis(2.0)不支持(association)
ibatis代码为(javaBean不变):
<resultMap class="institutionExpert" id="institutionExpertBaseResultMap"> <result property="id" column="ID" /> <result property="createBy" column="C_CREATE_BY" /> <result property="createDate" column="C_CREATE_DATE" /> <result property="updateBy" column="C_UPDATE_BY" /> <result property="updateDate" column="C_UPDATE_DATE" /> <result property="deleteFlag" column="C_DELETE_FLAG" /> <result property="expert" resultMap="namespace.expertBaseResultMap" column="C_EXPERT_ID"/> </resultMap><resultMap id="expertBaseResultMap" class="expert"> <result property="id" column="ID" /> </resultMap>变更了resultMap中result,在result中加入resultMap(这个resultMap要新增)。注意情况:在mybatis中,如果resultMap中有一列在查询的表中不存在,不会报错,而在ibatis中,则会报错。