resultMap 包含 association 和 collection

实体关系图

graph BT  
id2[SghnRemoteTeachCommentAndReplyInfo-list集合]-->|包含于|id1[GetRemoteTeachCommentListVO];  
id2-->|继承|id3[SghnRemoteTeachCommentInfo];
id3-->|继承|id4[SghnRemoteTeachComment];
id5[SghnRemoteTeachReplyInfo-list集合]-->|包含于|id2;
id5-->|继承|id7[SghnRemoteTeachReply];

实体定义

com.sinldo.api.business.getremoteteachcommentlist.vo.GetRemoteTeachCommentListVO
public class GetRemoteTeachCommentListVO {
    private Long commentCount;
    private List<SghnRemoteTeachCommentAndReplyInfo> list;

    public Long getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(Long commentCount) {
        this.commentCount = commentCount;
    }

    public List<SghnRemoteTeachCommentAndReplyInfo> getList() {
        return list;
    }

    public void setList(List<SghnRemoteTeachCommentAndReplyInfo> list) {
        this.list = list;
    }
}
com.sinldo.api.po.SghnRemoteTeachCommentAndReplyInfo
public class SghnRemoteTeachCommentAndReplyInfo extends SghnRemoteTeachCommentInfo{
    private Integer replyCount;
    private List<SghnRemoteTeachReplyInfo> replyList;

    public Integer getReplyCount() {
        return replyCount;
    }
    public void setReplyCount(Integer replyCount) {
        this.replyCount = replyCount;
    }

    public List<SghnRemoteTeachReplyInfo> getReplyList() {
        return replyList;
    }

    public void setReplyList(List<SghnRemoteTeachReplyInfo> replyList) {
        this.replyList = replyList;
    }
}

com.sinldo.api.po.SghnRemoteTeachCommentInfo
public class SghnRemoteTeachCommentInfo extends SghnRemoteTeachComment {
    private String commentName;
    private String commentSiteName;

    public String getCommentName() {
        return commentName;
    }

    public void setCommentName(String commentName) {
        this.commentName = commentName;
    }

    public String getCommentSiteName() {
        return commentSiteName;
    }

    public void setCommentSiteName(String commentSiteName) {
        this.commentSiteName = commentSiteName;
    }
}
com.sinldo.po.share.SghnRemoteTeachComment
public class SghnRemoteTeachComment {
    private Integer id;

    private Integer lectureId;

    private String commentVoip;

    private String comment;

    private Date commentTime;

    private String operation;

    private Date createTime;

    private Date updateTime;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getLectureId() {
        return lectureId;
    }

    public void setLectureId(Integer lectureId) {
        this.lectureId = lectureId;
    }

    public String getCommentVoip() {
        return commentVoip;
    }

    public void setCommentVoip(String commentVoip) {
        this.commentVoip = commentVoip;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Date getCommentTime() {
        return commentTime;
    }

    public void setCommentTime(Date commentTime) {
        this.commentTime = commentTime;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
com.sinldo.api.po.SghnRemoteTeachReplyInfo
public class SghnRemoteTeachReplyInfo extends SghnRemoteTeachReply {

    private String replyId;
    private String replyName;
    private String replySiteName;
    private String beReplyedName;
    private String beReplyedSiteName;

    public String getReplyId() {
        return replyId;
    }

    public void setReplyId(String replyId) {
        this.replyId = replyId;
    }

    public String getReplyName() {
        return replyName;
    }

    public void setReplyName(String replyName) {
        this.replyName = replyName;
    }

    public String getReplySiteName() {
        return replySiteName;
    }

    public void setReplySiteName(String replySiteName) {
        this.replySiteName = replySiteName;
    }


    public String getBeReplyedName() {
        return beReplyedName;
    }

    public void setBeReplyedName(String beReplyedName) {
        this.beReplyedName = beReplyedName;
    }

    public String getBeReplyedSiteName() {
        return beReplyedSiteName;
    }

    public void setBeReplyedSiteName(String beReplyedSiteName) {
        this.beReplyedSiteName = beReplyedSiteName;
    }
}
com.sinldo.po.share.SghnRemoteTeachReply
public class SghnRemoteTeachReply {
    private Integer id;

    private Integer commentId;

    private String replyVoip;

    private String reply;

    private String beReplyedVoip;

    private Integer beReplyedId;

    private Date replyTime;

    private String operation;

    private Date createTime;

    private Date updateTime;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCommentId() {
        return commentId;
    }

    public void setCommentId(Integer commentId) {
        this.commentId = commentId;
    }

    public String getReplyVoip() {
        return replyVoip;
    }

    public void setReplyVoip(String replyVoip) {
        this.replyVoip = replyVoip;
    }

    public String getReply() {
        return reply;
    }

    public void setReply(String reply) {
        this.reply = reply;
    }

    public String getBeReplyedVoip() {
        return beReplyedVoip;
    }

    public void setBeReplyedVoip(String beReplyedVoip) {
        this.beReplyedVoip = beReplyedVoip;
    }

    public Integer getBeReplyedId() {
        return beReplyedId;
    }

    public void setBeReplyedId(Integer beReplyedId) {
        this.beReplyedId = beReplyedId;
    }

    public Date getReplyTime() {
        return replyTime;
    }

    public void setReplyTime(Date replyTime) {
        this.replyTime = replyTime;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}

mapper 定义

<select id="getSghnRemoteTeachCommentAndReplyList" resultMap="get-getSghnRemoteTeachCommentAndReplyList">
    select com.lectureId as lectureId,com.commentVoip as commentVoip,com.comment as comment,
    com.commentTime as commentTime,
    com.id as commentId,per.name as commentName, si.siteName as commentSiteName
    from sghn_remote_teach_comment com
    left join personnel per on per.voip=com.commentVoip and (per.operation !='del' or per.operation is null)
    left join sites si on si.siteId=per.siteId
    where com.lectureId=#{lectureId}
    and (com.operation !='del' or com.operation is null)
    order by com.commentTime desc
</select>
<select id="getSghnRemoteTeachCommentAndReplyListCount" resultType="java.lang.Long">
    select count(0)
    from sghn_remote_teach_comment com
    left join personnel per on per.voip=com.commentVoip and (per.operation !='del' or per.operation is null)
    left join sites si on si.siteId=per.siteId
    where com.lectureId=#{lectureId}
    and (com.operation !='del' or com.operation is null)
</select>
<resultMap id="get-getSghnRemoteTeachCommentAndReplyList" type="com.sinldo.api.po.SghnRemoteTeachCommentAndReplyInfo">
	<result column="commentId"  property="id" />
	<result column="lectureId"  property="lectureId" />
	<result column="commentVoip"  property="commentVoip" />
	<result column="commentName"  property="commentName" />
	<result column="commentSiteName" property="commentSiteName"/>
	<result column="comment"  property="comment" />
	<result column="commentTime"  property="commentTime" />
	<association property="replyCount" column="commentId" javaType="integer" select="getSghnRemoteTeachReplyCount"/>
	<collection property="replyList" column="commentId" javaType="ArrayList"
				ofType="com.sinldo.api.po.SghnRemoteTeachReplyInfo" select="getSghnRemoteTeachReplyInfoList"/>
</resultMap>
<select id="getSghnRemoteTeachReplyCount" parameterType="integer" resultType="java.lang.Integer">
    select count(0)
     from sghn_remote_teach_reply reply
    left join personnel per on per.voip=reply.replyVoip and (per.operation !='del' or per.operation is null)
    left join sites si on si.siteId=per.siteId
    left join personnel bePer on bePer.voip=reply.beReplyedVoip and (bePer.operation !='del' or bePer.operation is null)
    left join sites beSi on beSi.siteId=bePer.siteId
    where reply.commentId=#{commentId}
    and (reply.operation !='del' or reply.operation is null)
</select>
<select id="getSghnRemoteTeachReplyInfoList" parameterType="integer"
            resultType="com.sinldo.api.po.SghnRemoteTeachReplyInfo">
    select top 3 reply.*,reply.id as replyId,per.name as replyName,si.siteName as replySiteName,
     bePer.name as beReplyedName,beSi.siteName as beReplyedSiteName
     from sghn_remote_teach_reply reply
    left join personnel per on per.voip=reply.replyVoip and (per.operation !='del' or per.operation is null)
    left join sites si on si.siteId=per.siteId
    left join personnel bePer on bePer.voip=reply.beReplyedVoip and (bePer.operation !='del' or bePer.operation is null)
    left join sites beSi on beSi.siteId=bePer.siteId
    where reply.commentId=#{commentId}
    and (reply.operation !='del' or reply.operation is null)
    order by reply.replyTime asc
</select>