78 lines
3.2 KiB
XML
78 lines
3.2 KiB
XML
<?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.ivmiku.tutorial.mapper.CommentMapper">
|
||
|
||
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Comment">
|
||
<id property="commentId" column="comment_id" jdbcType="BIGINT"/>
|
||
<result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/>
|
||
<result property="postId" column="post_id" jdbcType="BIGINT"/>
|
||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||
<result property="parentCommentId" column="parent_comment_id" jdbcType="BIGINT"/>
|
||
<result property="isDeleted" column="is_deleted" jdbcType="TINYINT"/>
|
||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||
<result property="mentionedUserId" column="mentioned_user_id" jdbcType="VARCHAR"/> <!-- 新增字段 -->
|
||
<result column="image_urls" property="imageUrls" />
|
||
<result column="video_url" property="videoUrl" />
|
||
</resultMap>
|
||
|
||
<sql id="Base_Column_List">
|
||
comment_id, user_openid, post_id, content,
|
||
parent_comment_id, is_deleted, created_at, updated_at,
|
||
mentioned_user_id, image_urls, video_url
|
||
</sql>
|
||
|
||
<!-- 查询指定帖子的所有评论 -->
|
||
<select id="selectCommentsByPostId" resultMap="BaseResultMap">
|
||
SELECT
|
||
<include refid="Base_Column_List"/>
|
||
FROM comment
|
||
WHERE post_id = #{postId} AND is_deleted = 0
|
||
</select>
|
||
|
||
<!-- 查询指定评论的所有回复 -->
|
||
<select id="selectRepliesByCommentId" resultMap="BaseResultMap">
|
||
SELECT
|
||
<include refid="Base_Column_List"/>
|
||
FROM comment
|
||
WHERE parent_comment_id = #{commentId} AND is_deleted = 0
|
||
</select>
|
||
|
||
<!-- 插入新的评论 -->
|
||
<insert id="insertComment" parameterType="com.ivmiku.tutorial.entity.Comment">
|
||
INSERT INTO comment (
|
||
user_openid, post_id, content, parent_comment_id,
|
||
is_deleted, created_at, updated_at, mentioned_user_id
|
||
) VALUES (
|
||
#{userOpenid}, #{postId}, #{content}, #{parentCommentId},
|
||
#{isDeleted}, #{createdAt}, #{updatedAt}, #{mentionedUserId}, #{imageUrls}, #{videoUrl}
|
||
)
|
||
</insert>
|
||
|
||
<!-- 更新评论 -->
|
||
<update id="updateComment" parameterType="com.ivmiku.tutorial.entity.Comment">
|
||
UPDATE comment
|
||
SET
|
||
user_openid = #{userOpenid},
|
||
post_id = #{postId},
|
||
content = #{content},
|
||
parent_comment_id = #{parentCommentId},
|
||
is_deleted = #{isDeleted},
|
||
created_at = #{createdAt},
|
||
updated_at = #{updatedAt},
|
||
mentioned_user_id = #{mentionedUserId},
|
||
image_urls = #{imageUrls},
|
||
video_url = #{videoUrl}
|
||
WHERE comment_id = #{commentId}
|
||
</update>
|
||
|
||
<!-- 删除评论,实际上是将is_deleted字段设置为1 -->
|
||
<update id="deleteComment">
|
||
UPDATE comment
|
||
SET is_deleted = 1, updated_at = CURRENT_TIMESTAMP
|
||
WHERE comment_id = #{commentId}
|
||
</update>
|
||
</mapper>
|