您的位置:首页 > 其它

mybatis在关联映射中,引入外部xml文件中定义的对象

2017-03-15 00:00 344 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MyBatis 映射