Mybatis 中的一对一,一对多,多对多的配置原则

表:market_plan(营销计划(关联了用户))

market_plan_product(产品关联营销计划)

market_plan_label(标签关联营销计划)

market_plan_ideadata(创意素材关联营销计划)

user_ideadata_activity(活动关联用户,活动关联创意素材表)

user(用户表)

配置原则:A关联B,将A的resultMap关联(association)到B的resultMap中,这样才能在写关联查询sql语句的时候,查询出A,B表中的属性。多张表的关联也是一样的道理!

配置xml示例:

<resultMap id="userResultMap" type="com.mchuan.fastmarketplat.b.entity.User">
<id column="USER_ID" property="id" />
<result column="ACCOUNT" property="account" />
<result column="NAME" property="name" />
<result column="MOBILE" property="mobile" />
</resultMap>


<resultMap id="labelResultMap"
type="com.mchuan.fastmarketplat.b.entity.MarketPlanLabel">
<id property="id" column="LABEL_ID" />
<result property="gender" column="GENDER" />
<result property="area" column="AREA" />
<result property="age" column="AGE" />
<result property="deviceType" column="DEVICE_TYPE" />
<result property="communicationFee" column="COMMUNICATION_FEE" />
<result property="actionLabels" column="ACTION_LABELS" />
<result property="netScene" column="NET_SCENE" />
</resultMap>


<resultMap id="productResultMap"
type="com.mchuan.fastmarketplat.b.entity.MarketPlanProduct">
<id property="id" column="PRODUCT_ID" />
<result property="coverAmount" column="COVER_AMOUNT" />
</resultMap>


<resultMap id="activityResultMap"
type="com.mchuan.fastmarketplat.b.entity.UserActivity">
<id column="AC_ID" property="id" />
<result column="ACTIVITY_ID" property="activityId" jdbcType="INTEGER" />
<result column="COVER_URL" property="coverUrl" jdbcType="VARCHAR" />
<result column="ACTIVITY_URL" property="activityUrl" jdbcType="VARCHAR" />
<result column="VIEW_URL" property="viewUrl" jdbcType="VARCHAR" />
<result column="CREATE_TIME" property="createTime" />
<result column="UPDATE_TIME" property="updateTime" />
</resultMap>


<resultMap id="ideaDataResultMap"
type="com.mchuan.fastmarketplat.b.entity.MarketPlanIdeaData">
<id property="id" column="IDEA_DATA_ID" />
<result property="content" column="CONTENT" />
<result property="linkUrl" column="LINK_URL" />
<!-- ideaData关联属性 -->
<association property="userActivity"
javaType="com.mchuan.fastmarketplat.b.entity.UserActivity" resultMap="activityResultMap" />
</resultMap>


<resultMap id="BaseResultMap" type="com.mchuan.fastmarketplat.b.entity.MarketPlan">
<id column="ID" property="id" jdbcType="INTEGER" />
<result column="PLAN_NAME" property="planName" jdbcType="VARCHAR" />
<result column="BUDGET" property="budget" jdbcType="DECIMAL" />
<result column="ACTUAL_BUDGET" property="actualBudget"
jdbcType="DECIMAL" />
<result column="DEMAND_TYPE" property="demandType" jdbcType="VARCHAR" />
<result column="START_DATE" property="startDate" />
<result column="END_DATE" property="endDate" />
<result column="CREATE_STATUS" property="createStatus"
jdbcType="INTEGER" />
<result column="CREATE_TIME" property="createTime" />
<result column="UPDATE_TIME" property="updateTime" />
<result column="NOTE" property="note" jdbcType="VARCHAR" />
<result column="STATUS" property="status" jdbcType="INTEGER" />
<result column="DESTPAGE_URL" property="destpageUrl" jdbcType="VARCHAR" />
<result column="IS_AWARD" property="isAward" jdbcType="INTEGER" />
<result column="AWARD_MONEY" property="awardMoney" jdbcType="DECIMAL" />
<result column="ADVERTISER" property="advertiser" jdbcType="VARCHAR" />
<result column="INDUSTRY" property="industry" jdbcType="INTEGER" />


<!-- marketPlan关联属性 -->
<association property="user"
javaType="com.mchuan.fastmarketplat.b.entity.User" resultMap="userResultMap" />
<association property="marketPlanLabel"
javaType="com.mchuan.fastmarketplat.b.entity.MarketPlanLabel"
resultMap="labelResultMap" />
<association property="marketPlanProduct"
javaType="com.mchuan.fastmarketplat.b.entity.MarketPlanProduct"
resultMap="productResultMap" />
<association property="marketPlanIdeaData"
javaType="com.mchuan.fastmarketplat.b.entity.MarketPlanIdeaData"
resultMap="ideaDataResultMap" />
</resultMap>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值