<!--    通过文章id递归查询所有评论 -->
<select id="findByArticleId" resultMap="commentResultMap">
    SELECT * FROM mxg_comment WHERE parent_id = -1
    AND article_id = #{articleId}
    ORDER BY create_date DESC
</select>

<!--    将每条一级评论的id作为parentId来查询子评论-->
<select id="findByParentId" resultMap="commentResultMap">
    SELECT * FROM mxg_comment WHERE parent_id = #{id}
</select>

<resultMap id="commentResultMap" type="Comment" >
    <id column="id" property="id"/>
    <result column="parent_id" property="parentId"/>
    <result column="user_id" property="userId"/>
    <result column="nick_name" property="nickName"/>
    <result column="user_image" property="userImage"/>
    <result column="article_id" property="articleId"/>
    <result column="content" property="content"/>
    <result column="create_date" property="createDate"/>
    <collection property="children" javaType="list" ofType="Comment"
                column="id" select="findByParentId"/>
</resultMap>
06-25 00:54