夜雨声烦 | 5c9d131 | 2025-04-23 17:46:19 +0800 | [diff] [blame] | 1 | package com.example.g8backend.mapper; |
| 2 | |
| 3 | import com.example.g8backend.entity.Comment; |
| 4 | import org.apache.ibatis.annotations.*; |
| 5 | |
| 6 | import java.util.List; |
| 7 | |
| 8 | @Mapper |
| 9 | public interface CommentMapper { |
| 10 | |
| 11 | // 插入评论 |
| 12 | @Insert("INSERT INTO comments (post_id, user_id, content, parent_comment_id) VALUES (#{postId}, #{userId}, #{content}, #{parentCommentId})") |
| 13 | int insert(Comment comment); |
| 14 | |
| 15 | // 获取顶级评论 |
| 16 | @Select("SELECT * FROM comments WHERE post_id = #{postId} AND parent_comment_id IS NULL ORDER BY created_at DESC") |
| 17 | List<Comment> findTopLevelCommentsByPostId(Long postId); |
| 18 | |
| 19 | // 获取某个父评论ID对应的子评论 |
| 20 | @Select("SELECT * FROM comments WHERE parent_comment_id = #{parentCommentId} ORDER BY created_at DESC") |
| 21 | List<Comment> findRepliesByParentCommentId(Long parentCommentId); |
| 22 | |
| 23 | // 删除评论 |
| 24 | @Delete("DELETE FROM comments WHERE comment_id = #{commentId}") |
| 25 | int deleteById(Long commentId); |
| 26 | } |