添加Comment相关文件
Change-Id: I823c09a1b576af5b176538f45b30e81cc7789550
diff --git a/src/main/resources/mapper/CommentMapper.xml b/src/main/resources/mapper/CommentMapper.xml
new file mode 100644
index 0000000..81e4581
--- /dev/null
+++ b/src/main/resources/mapper/CommentMapper.xml
@@ -0,0 +1,54 @@
+<?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.pt5.pthouduan.mapper.CommentMapper">
+
+ <!-- 创建评论 -->
+ <insert id="save" parameterType="com.pt5.pthouduan.entity.Comment">
+ INSERT INTO comment (commentid, userid, postid, post_commentcontent, commenttime)
+ VALUES (#{commentid}, #{userid}, #{postid}, #{postCommentcontent}, #{commenttime})
+ </insert>
+
+ <!-- 删除评论 -->
+ <delete id="deleteByCommentid" parameterType="int">
+ DELETE FROM comment WHERE commentid = #{commentid}
+ </delete>
+
+ <!-- 更新评论 -->
+ <update id="updateComment" parameterType="com.pt5.pthouduan.entity.Comment">
+ UPDATE comment
+ SET userid = #{userid},
+ postid = #{postid},
+ post_commentcontent = #{postCommentcontent},
+ commenttime = #{commenttime}
+ WHERE commentid = #{commentid}
+ </update>
+
+ <!-- 按帖子ID查询所有评论 -->
+ <select id="selectByPostid" parameterType="int" resultType="com.pt5.pthouduan.entity.Comment">
+ SELECT * FROM comment
+ WHERE postid = #{postid}
+ ORDER BY commenttime ASC
+ </select>
+
+ <!-- 点赞 +1 -->
+ <update id="incrementLikes" parameterType="int">
+ UPDATE comment
+ SET likes = likes + 1
+ WHERE commentid = #{commentid}
+ </update>
+
+ <!-- 取消点赞 -1(最小为0) -->
+ <update id="decrementLikes" parameterType="int">
+ UPDATE comment
+ SET likes = CASE
+ WHEN likes > 0 THEN likes - 1
+ ELSE 0
+ END
+ WHERE commentid = #{commentid}
+ </update>
+
+
+</mapper>