vlog/book-mapper/src/main/resources/mapper/CommentMapperCustom.xml
2025-03-14 11:30:58 +08:00

46 lines
1.5 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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.imooc.mapper.CommentMapperCustom" >
<!--
FIXME
思考:阿里规范明确规定不能超过三表关联,这里达到了四张表
我们应该如何优化呢使得sql脚本查询表位三表或者两表查询
来实现呢又或者说我们能不能不使用数据库使用别的手段中间件mycat
-->
<select id="getCommentList" parameterType="map" resultType="com.imooc.vo.CommentVO">
SELECT
c.id as commentId,
c.vlog_id as vlogId,
u.id as vlogerId,
u.nickname as commentUserNickname,
u.face as commentUserFace,
c.father_comment_id as fatherCommentId,
c.comment_user_id as commentUserId,
c.content as content,
c.like_counts as likeCounts,
fu.nickname as replyedUserNickname,
c.create_time as createTime
FROM
`t_comment` as c
LEFT JOIN
t_users as u
ON
c.comment_user_id = u.id
LEFT JOIN
`t_comment` as fc
ON
c.father_comment_id = fc.id
LEFT JOIN
t_users as fu
ON
fc.comment_user_id = fu.id
WHERE
c.vlog_id = #{paramMap.vlogId}
ORDER BY
c.like_counts DESC,
c.create_time DESC
</select>
</mapper>