| <?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> |