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
相关文章推荐
- 3.2 mybatis.config.xml_properties_引入外部配置文件
- mybatis 引入外部属性文件 别名配置 映射文件配置
- web.xml文件中定义和映射Servlet(2/3)
- hibernate映射文件XXX.hbm.xml配置映射元素详解--对象标识符(OID)
- MyBatis 入门到精通(二) SQL语句映射XML文件
- ASP.NET中母版页引用外部js或css文件无效,提示对象未定义解决方法
- XML配置中 引入外部property文件
- web.xml 文件中定义和映射Servlet(1/3)
- XML映射文件中的DTD定义(Hibernate初始化导入*.hbm.xm慢的问题)
- spring.xml从外部文件引入数据库配置信息
- 通过struts.xml配置映射后的jsp引入外部css和js的路径问题及css中图片url路径问题
- 使用Digester解析XML文件和JAVA对象的映射
- MyBatis映射文件的resultMap如何做表关联
- MyBatis映射文件的resultMap如何做表关联
- JXTree对象,读取外部xml文件数据,生成树的函数
- xml引入外部文件DTD
- Spring、MyBatis的整合数据映射器类(UserMapper->iocContext.xml)配置文件详解
- MyBatis XML 映射配置文件
- mybatis逆向工程生成xml映射文件
- VO对象通过groovy模板映射XML文件