mybatis 关联查询 一对一 一对多

</pre><pre name="code" class="java">

当前对象的xml设置中

返回类型

    <resultMap id="releaseUnitMap" type="com.afocus.fa.release.model.ReleaseUnit">
        <result property="id" column="ID"></result>
        <result property="name" column="NAME"></result>
        <result property="platformId" column="PLATFORM_ID"></result>
        <result property="categoryId" column="CATEGORY_ID"></result>
        <result property="brandId" column="BRAND_ID"></result>
        <result property="goodsName" column="GOODS_NAME"></result>
        <result property="originalPrice" column="ORIGINAL_PRICE"></result>
        <result property="presentPrice" column="PRESENT_PRICE"></result>
        <result property="type" column="TYPE"></result>
        <result property="status" column="STATUS"></result>
        <result property="createTime" column="CREATE_TIME"></result>
        <result property="updateTime" column="UPDATE_TIME"></result>
        <result property="creatorId" column="CREATOR_ID"></result>
        <result property="creatorName" column="CREATOR_NAME"></result>
        <result property="categoryName" column="categoryName"></result>
        <result property="brandName" column="brandName"></result>
        <result property="platformName" column="platformName"></result>
        <!-- 其他定义字段 -->
        <result property="searchStartTime" column=""></result>
        <result property="searchEndTime" column=""></result>
        <!-- 投放地域数据 通用  一对一-->
        <association property=" releaseArea"
            javaType="com.afocus.fa.release.model.ReleaseArea"
            resultMap="com.afocus.fa.release.dao.ReleaseAreaDao. globalReleaseArea"/>
        <!-- 天猫直通车投放方式数据 一对多 -->
        <collection property=" tmztcReleaseWays"
            ofType="com.afocus.fa.release.model.ReleaseTmztcWay"
            resultMap="com.afocus.fa.release.dao.ReleaseTmztcWayDao.globalReleaseTmztcWay"/>
        <!-- 天猫直通车投放时间数据 -->
        <collection property=" tmztcReleaseTimes"
            ofType="com.afocus.fa.release.model.ReleaseTmztcTime"
            resultMap="com.afocus.fa.release.dao.ReleaseTmztcTimeDao.globalReleaseTmztcTime"/>
        

    </resultMap>


查询语句

<select id="loadTmztcInformation" resultMap="releaseUnitMap">        
        SELECT <include refid="field"/>,
            MC.NAME categoryName,MB.NAME brandName,MP.NAME platformName,
            <include refid="com.afocus.fa.release.dao.ReleaseTmztcWayDao.globalField"/>,
            <include refid="com.afocus.fa.release.dao.ReleaseTmztcTimeDao.globalField"/>,
            <include refid="com.afocus.fa.release.dao.ReleaseAreaDao.globalField"/>
        FROM FA_RELEASE_UNIT RU
        LEFT JOIN (SELECT * FROM FA_MANAGE_CATEGORY CA WHERE CA.STATUS != -1) MC
         ON RU.CATEGORY_ID = MC.ID
        LEFT JOIN (SELECT * FROM FA_MANAGE_BRAND BR WHERE BR.STATUS !=1) MB
         ON RU.BRAND_ID = MB.ID
        LEFT JOIN (SELECT * FROM FA_MANAGE_PLATFORM PL WHERE PL.STATUS!=-1) MP
        ON MP.ID =RU.PLATFORM_ID
        LEFT JOIN (SELECT * FROM FA_RELEASE_TMZTC_WAY WA WHERE WA.STATUS !=-1) RTW
         ON RTW.UNIT_ID=RU.ID
        LEFT JOIN (SELECT * FROM FA_RELEASE_TMZTC_TIME T WHERE T.STATUS !=-1) RTT
        ON RTT.UNIT_ID=RU.ID
        LEFT JOIN (SELECT * FROM FA_RELEASE_AREA A WHERE A.STATUS !=-1) RA
        ON RA.UNIT_ID=RU.ID
        <include refid="dynamicWhere" />
    </select>

当前对象的model中

    private ReleaseArea releaseArea;
    
    private List<ReleaseTmztcWay> tmztcReleaseWays;

    private List<ReleaseTmztcTime> tmztcReleaseTimes;   


投放地域的xml 注意对应样色相同的相互对应

    <sql id="globalField">
        RA.ID RA_ID, RA.UNIT_ID RA_UNIT_ID, RA.PROVINCE, RA.TYPE RA_TYPE, RA.STATUS RA_STATUS,
        RA.CREATE_TIME RA_CREATE_TIME, RA.UPDATE_TIME RA_UPDATE_TIME, RA.CREATOR_ID RA_CREATOR_ID, RA.CREATOR_NAME RA_CREATOR_NAME
    </sql>

<resultMap id="globalReleaseArea" type="com.afocus.fa.release.model.ReleaseArea">
        <result property="id" column="RA_ID"></result>
        <result property="unitId" column="RA_UNIT_ID"></result>
        <result property="province" column="PROVINCE"></result>
        <result property="type" column="RA_TYPE"></result>
        <result property="status" column="RA_STATUS"></result>
        <result property="createTime" column="RA_CREATE_TIME"></result>
        <result property="updateTime" column="RA_UPDATE_TIME"></result>
        <result property="creatorId" column="RA_CREATOR_ID"></result>
        <result property="creatorName" column="RA_CREATOR_NAME"></result>
    </resultMap>
   

其他的xml也就和投放地域的设置相同





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值