81,122
社区成员




// 公司
<resultMap id="BaseResultMap" type="Company" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="address" property="address" jdbcType="VARCHAR" />
<association property="area" column="id" javaType="Area" resultMap="AreaMapper.BaseResultMap"/>
</resultMap>
// 区域
<resultMap id="BaseResultMap" type="Area">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="area_name" property="name" jdbcType="VARCHAR" />
</resultMap>
如果执行关联查询SQL,获得的company对象打印结果如下
Company [id=18, address=测试, area=Area [id=18, name=北京]] // 实际area的id为1
公司里的区域id会一直与公司id保持一样. 当然如果将数据库的区域id使用areaid区分开来,结果就是正确的.
想问的就是如果数据库都用id字段,且java类也用id,怎样才能得到正确的数据呢