ym923 | 55ec83a | 2025-06-03 17:15:13 +0800 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <!DOCTYPE mapper |
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 5 | |
| 6 | <mapper namespace="com.pt5.pthouduan.mapper.CommentMapper"> |
| 7 | |
| 8 | <!-- 创建评论 --> |
| 9 | <insert id="save" parameterType="com.pt5.pthouduan.entity.Comment"> |
| 10 | INSERT INTO comment (commentid, userid, postid, post_commentcontent, commenttime) |
| 11 | VALUES (#{commentid}, #{userid}, #{postid}, #{postCommentcontent}, #{commenttime}) |
| 12 | </insert> |
| 13 | |
| 14 | <!-- 删除评论 --> |
| 15 | <delete id="deleteByCommentid" parameterType="int"> |
| 16 | DELETE FROM comment WHERE commentid = #{commentid} |
| 17 | </delete> |
| 18 | |
| 19 | <!-- 更新评论 --> |
| 20 | <update id="updateComment" parameterType="com.pt5.pthouduan.entity.Comment"> |
| 21 | UPDATE comment |
| 22 | SET userid = #{userid}, |
| 23 | postid = #{postid}, |
| 24 | post_commentcontent = #{postCommentcontent}, |
| 25 | commenttime = #{commenttime} |
| 26 | WHERE commentid = #{commentid} |
| 27 | </update> |
| 28 | |
| 29 | <!-- 按帖子ID查询所有评论 --> |
| 30 | <select id="selectByPostid" parameterType="int" resultType="com.pt5.pthouduan.entity.Comment"> |
| 31 | SELECT * FROM comment |
| 32 | WHERE postid = #{postid} |
| 33 | ORDER BY commenttime ASC |
| 34 | </select> |
| 35 | |
| 36 | <!-- 点赞 +1 --> |
| 37 | <update id="incrementLikes" parameterType="int"> |
| 38 | UPDATE comment |
| 39 | SET likes = likes + 1 |
| 40 | WHERE commentid = #{commentid} |
| 41 | </update> |
| 42 | |
| 43 | <!-- 取消点赞 -1(最小为0) --> |
| 44 | <update id="decrementLikes" parameterType="int"> |
| 45 | UPDATE comment |
| 46 | SET likes = CASE |
| 47 | WHEN likes > 0 THEN likes - 1 |
| 48 | ELSE 0 |
| 49 | END |
| 50 | WHERE commentid = #{commentid} |
| 51 | </update> |
| 52 | |
| 53 | |
| 54 | </mapper> |