mybatis 一对一 一对多查询

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxx.mapper.TestMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.xxx.entity.dto.TestDTO">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="from_type" property="fromType" />
        <result column="tools_type" property="toolsType" />
        <result column="name" property="name" />
        <result column="description" property="description" />
        <result column="work_time" property="workTime" />
        <result column="work_addr" property="workAddr" />
        <result column="content" property="content" />
        <result column="is_notice" property="isNotice" />
        <result column="msg_notice" property="msgNotice" />
        <result column="sms_notice" property="smsNotice" />
        <result column="notice_scope" property="noticeScope" />
        <result column="notice_info" property="noticeInfo" />
        <result column="is_share" property="isShare" />
        <result column="share_url" property="shareUrl" />
        <result column="is_sync" property="isSync" />
        <result column="from_id" property="fromId" />
        <result column="status" property="status" />
        <result column="creator_id" property="creatorId" />
        <result column="updated_at" property="updatedAt" />
        <result column="is_delete" property="isDelete" />
        <association  property="hoster" javaType="com.xxx.entity.TestUser" column="{mtsId=id}" select="selectUserByMtsId3" />
        <collection  property="userList1" ofType="com.xxx.entity.TestUser" column="{mtsId=id}" select="selectUserByMtsId1" />
        <collection  property="userList2" ofType="com.xxx.entity.TestUser" column="{mtsId=id}" select="selectUserByMtsId2" />
        <collection  property="postList"  ofType="com.xxx.entity.TestPost" column="{mtsId=id}" select="selectPostByMtsId"/>
        <collection  property="noticeList"  ofType="String" column="{mtsId=id}" select="selectUserNoticeByMtsId"/>
    </resultMap>
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, from_type, tools_type, name, description, work_time, work_addr, hoster, content, is_notice, msg_notice, sms_notice,
        notice_scope, notice_info, is_share, share_url, is_sync, from_id, creator_id, created_at, updated_at, is_delete
    </sql>

    <select id="getTestInfo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>,if(work_time > now(),1,2) status
        from yc_meet_talk_study
        where id=#{id}
    </select>
    <select id="selectPostByMtsId" resultType="com.xxx.entity.TestPost">
        select id, mts_id, org_uuid, org_name, path_code, org_code, sys_code, parent_org_uuid, creator_id, created_at, updated_at, is_delete
        from yc_meet_talk_study_post
        where mts_id=#{mtsId} and is_delete=0
    </select>
    <select id="selectUserByMtsId1" resultType="com.xxx.entity.TestUser">
        select a.id, a.mts_id, a.account_uuid, a.org_uuid, a.org_name, a.path_code, a.org_code, a.sys_code, a.user_type, b.person_name
        from yc_meet_talk_study_user a left join uc_uu_personinfo b on a.account_uuid=b.account_uuid
        where a.mts_id=#{mtsId} and a.user_type=1 and a.is_delete=0
    </select>
    <select id="selectUserByMtsId2" resultType="com.xxx.entity.TestUser">
        select a.id, a.mts_id, a.account_uuid, a.org_uuid, a.org_name, a.path_code, a.org_code, a.sys_code, a.user_type, b.person_name
        from yc_meet_talk_study_user a left join uc_uu_personinfo b on a.account_uuid=b.account_uuid
        where a.mts_id=#{mtsId} and a.user_type=2 and a.is_delete=0
    </select>
    <select id="selectUserByMtsId3" resultType="com.xxx.entity.TestUser">
        select a.id, a.mts_id, a.account_uuid, a.org_uuid, a.org_name, a.path_code, a.org_code, a.sys_code, a.user_type, b.person_name
        from yc_meet_talk_study_user a left join uc_uu_personinfo b on a.account_uuid=b.account_uuid
        where a.mts_id=#{mtsId} and a.user_type=6 and a.is_delete=0
    </select>
    <select id="selectUserNoticeByMtsId" resultType="String">
        select distinct a.account_uuid
        from yc_meet_talk_study_user a
        where a.mts_id=#{mtsId} and a.is_delete=0 and notice_flag=1
    </select>
</mapper>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值