association标签
在mybatis中,关联映射是通过association标签实现的。
Lottery2Rule对象的Lottery2RuleDao.xml文件
<mapper namespace="cn.com.magicwifi.bz.betting.dao.Lottery2RuleDao">
<!-- 返回结果映射 -->
<resultMap id="BaseResultMap" type="cn.com.magicwifi.bz.betting.entity.Lottery2Rule">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="activity_id" property="activityId" jdbcType="INTEGER"/>
<result column="prize_id" property="prizeId" jdbcType="INTEGER"/>
<result column="rate" property="rate" jdbcType="INTEGER"/>
<result column="count" property="count" jdbcType="INTEGER"/>
<result column="remain_count" property="remainCount" jdbcType="INTEGER"/>
<result column="create_at" property="createAt" jdbcType="TIMESTAMP"/>
</resultMap>
</mapper>
Lottery2Activity对象的Lottery2ActivityDao.xml文件
<mapper namespace="cn.com.magicwifi.bz.betting.dao.Lottery2ActivityDao">
<!-- 返回结果映射 -->
<resultMap id="BaseResultMap" type="cn.com.magicwifi.bz.betting.entity.Lottery2Activity">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="content" property="content" jdbcType="VARCHAR"/>
<result column="start_date" property="startDate" jdbcType="TIMESTAMP"/>
<result column="end_date" property="endDate" jdbcType="TIMESTAMP"/>
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="create_at" property="createAt" jdbcType="TIMESTAMP"/>
</resultMap>
<!-- 使用resultMap映射实体类和字段之间的一一对应关系 -->
<resultMap id="selectContainPrize" extends="BaseResultMap" type="cn.com.magicwifi.bz.betting.entity.Lottery2Rule" >
<!-- 映射奖品 -->
<!-- 在association 标签中,定义resultMap属性,属性值的前缀是奖品的命名空间,后面接定义的Id -->
<association property="lottery2Prize" resultMap="cn.com.magicwifi.bz.betting.dao.Lottery2PrizeDao.BaseResultMap" javaType="cn.com.magicwifi.bz.betting.entity.Lottery2Prize">
</association>
</resultMap>
</mapper>
说明 cn.com.magicwifi.bz.betting.dao.Lottery2PrizeDao 这部分是Lottery2RuleDao.xml文件中的命名空间 BaseResultMap这个是Lottery2RuleDao.xml文件中定义的Id