0


Mybatis嵌套查询(一对多)

一、返回数据Java类

@DatapublicclassPersonnelDetailsVO{/**
     * 主键
     */@Column(name ="ID", length =36, precision =0)privateString id;/**
     * 人员姓名
     */@Column(name ="OPERATE_NAME", length =36, precision =0)privateString operateName;/**
     * 单位id
     */@Column(name ="UNIT_ID", length =36, precision =0)privateString unitId;/**
     * 单位名称
     */@Column(name ="UNIT_NAME", length =36, precision =0)privateString unitName;/**
     * 身份证号
     */@Column(name ="IDCARD", length =40, precision =0)privateString idcard;/**
     * 人员照片附件id
     */@Column(name ="PHOTO_ATT", length =36, precision =0)privateString photoAtt;/**
     * 联系电话
     */@Column(name ="PHONE", length =20, precision =0)privateString phone;/**
     * 人员状态
     */privateString operStatus;/**
     * 进场时间
     */privateTimestamp inTime;/**
     * 退场时间
     */privateTimestamp outTime;/**
     * 人员类型id
     */privateString personTypeId;/**
     * 人员类型名称
     */privateString personTypeName;/**
     * 项目部/班组ID
     */privateString teamId;/**
     * 项目部/班组名称
     */privateString teamName;/**
     * 证书信息列表
     */privateList<OperCertificateVO> certificateList;/**
     * 履历列表
     */privateList<OperResumeVO> resumeList;/**
     * 黑名单列表
     */privateList<OperBlacklistVO> blacklists;}

二、Mybatis代码

<resultMapid="personnelDetailsMap"type="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.PersonnelDetailsVO"><idcolumn="ID"property="id"/><resultcolumn="OPERATE_NAME"property="operateName"/><resultcolumn="UNIT_ID"property="unitId"/><resultcolumn="UNIT_NAME"property="unitName"/><resultcolumn="IDCARD"property="idcard"/><resultcolumn="PHOTO_ATT"property="photoAtt"/><resultcolumn="PHONE"property="phone"/><resultcolumn="OPER_STATUS"property="operStatus"/><resultcolumn="IN_TIME"property="inTime"/><resultcolumn="OUT_TIME"property="outTime"/><resultcolumn="PERSON_TYPE_ID"property="personTypeId"/><resultcolumn="PERSON_TYPE_NAME"property="personTypeName"/><resultcolumn="TEAM_ID"property="teamId"/><resultcolumn="TEAM_NAME"property="teamName"/><collectionproperty="certificateList"ofType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperCertificateVO"javaType="list"column="id"select="selectCertificateListByOperateId"/><collectionproperty="resumeList"ofType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperResumeVO"javaType="list"column="id"select="selectResumeListByOperateId"/><collectionproperty="blacklists"ofType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperBlacklistVO"javaType="list"column="id"select="selectBlacklistsByOperateId"/></resultMap><selectid="queryPersonnelDetails"resultMap="personnelDetailsMap"parameterType="java.util.List">
        select T1.ID,
               T1.OPERATE_NAME,
               T1.UNIT_ID,
               T1.UNIT_NAME,
               T1.IDCARD,
               T1.PHOTO_ATT,
               T1.PHONE,
               T2.OPER_STATUS,
               T2.IN_TIME,
               T2.OUT_TIME,
               T2.PERSON_TYPE_ID,
               T2.PERSON_TYPE_NAME,
               T2.TEAM_ID,
               T2.TEAM_NAME
        from XMXL_WL_OPER_ITEM T1
            left join XMXL_WL_PRO_OPER T2 on T1.ID = T2.OPERATE_ID
        where
            T1.ID IN
            <foreachcollection="list"index="index"item="item"open="("separator=","close=")">
                #{item}
            </foreach>
        order by T1.CREATE_TIME DESC
    </select><selectid="selectCertificateListByOperateId"resultType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperCertificateVO"parameterType="java.lang.String">
        select T1.ID                     AS id,
               T1.OPERATE_ID             AS operateId,
               T1.CERTIFICATE_ATT_ID    AS certificateAttId,
               T1.CERTIFICATE_TYPE      AS certificateType,
               T1.CERTIFICATE_NAME      AS certificateName,
               T1.CERTIFICATE_UNIT      AS certificateUnit,
               T1.ISSUANCE_DATE          AS issuanceDate,
               T1.EFFECTIVE_DATE         AS effectiveDate,
               T1.CREATOR_ID             AS creatorId,
               T1.UPDATOR_ID             AS updatorId,
               T1.CREATE_TIME            AS createTime,
               T1.UPDATE_TIME            AS updateTime
        from XMXL_WL_OPER_CERTIFICATE T1
        where T1.OPERATE_ID = #{id}
        order by T1.CREATE_TIME DESC
    </select><selectid="selectResumeListByOperateId"resultType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperResumeVO"parameterType="java.lang.String">
        select T1.ID                     AS id,
               T1.OPERATE_ID             AS operateId,
               T1.RESUME_IN_TIME         AS resumeInTime,
               T1.RESUME_OUT_TIME        AS resumeOutTime,
               T1.RESUME_PRO_NAME        AS resumeProName,
               T1.RESUME_SINGLE_PRO_NAME AS resumeSingleProName,
               T1.RESUME_PERSONNEL_TYPE  AS resumePersonnelType,
               T1.RESUME_PRO_STATUS      AS resumeProStatus,
               T1.CREATOR_ID             AS creatorId,
               T1.UPDATOR_ID             AS updatorId,
               T1.CREATE_TIME            AS createTime,
               T1.UPDATE_TIME            AS updateTime
        from XMXL_WL_OPER_RESUME T1
        where T1.OPERATE_ID = #{id}
        order by T1.CREATE_TIME DESC
    </select><selectid="selectBlacklistsByOperateId"resultType="com.mdxc.zhgd.overview.personnelmanage.personnelmanageapi.model.OperBlacklistVO"parameterType="java.lang.String">
        select T1.ID                          AS id,
               T1.OPERATE_ID                  AS operateId,
               T1.BLACKLIST_PRO_NAME          AS blacklistProName,
               T1.BLACKLIST_SINGLE_PRO_NAME   AS blacklistSingleProName,
               T1.BLACKLIST_BID_NAME          AS blacklistBidName,
               T1.KEEPOUT_DATE                AS keepoutDate,
               T1.KEEPOUT_EFFECTIVE_DATE      AS keepoutEffectiveDate,
               T1.KEEPOUT_REASON              AS keepoutReason,
               T1.CREATOR_ID                  AS creatorId,
               T1.UPDATOR_ID                  AS updatorId,
               T1.CREATE_TIME                 AS createTime,
               T1.UPDATE_TIME                 AS updateTime
        from XMXL_WL_OPER_BLACKLIST T1
        where T1.OPERATE_ID = #{id}
        order by T1.CREATE_TIME DESC
    </select>
标签: mybatis java 一对多

本文转载自: https://blog.csdn.net/weixin_46990523/article/details/132082137
版权归原作者 A Everyman 所有, 如有侵权,请联系我们删除。

“Mybatis嵌套查询(一对多)”的评论:

还没有评论