mybatis 一对一 一对多查询


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>

你可能感兴趣的:(mybatis,mysql,数据库)