|
|
<?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">
|
|
|
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.CommentMapper的命名空间,用于组织SQL语句 -->
|
|
|
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.CommentMapper">
|
|
|
<!-- 定义了一个resultMap,用于映射数据库列和Java对象属性 -->
|
|
|
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
<id column="comment_id" property="commentId" jdbcType="INTEGER"/> <!-- 评论ID -->
|
|
|
<result column="comment_pid" property="commentPid" jdbcType="INTEGER"/> <!-- 评论父ID -->
|
|
|
<result column="comment_pname" property="commentPname" jdbcType="VARCHAR"/> <!-- 评论父名称 -->
|
|
|
<result column="comment_article_id" property="commentArticleId" jdbcType="INTEGER"/> <!-- 文章ID -->
|
|
|
<result column="comment_author_name" property="commentAuthorName" jdbcType="VARCHAR"/> <!-- 评论作者名称 -->
|
|
|
<result column="comment_author_email" property="commentAuthorEmail" jdbcType="VARCHAR"/> <!-- 评论作者邮箱 -->
|
|
|
<result column="comment_author_url" property="commentAuthorUrl" jdbcType="VARCHAR"/> <!-- 评论作者网址 -->
|
|
|
<result column="comment_author_avatar" property="commentAuthorAvatar" jdbcType="VARCHAR"/> <!-- 评论作者头像 -->
|
|
|
<result column="comment_content" property="commentContent" jdbcType="VARCHAR"/> <!-- 评论内容 -->
|
|
|
<result column="comment_agent" property="commentAgent" jdbcType="VARCHAR"/> <!-- 评论代理 -->
|
|
|
<result column="comment_ip" property="commentIp" jdbcType="VARCHAR"/> <!-- 评论IP -->
|
|
|
<result column="comment_create_time" property="commentCreateTime" jdbcType="TIMESTAMP"/> <!-- 评论创建时间 -->
|
|
|
<result column="comment_role" property="commentRole" jdbcType="INTEGER"/> <!-- 评论角色 -->
|
|
|
<result column="comment_user_id" property="commentUserId" jdbcType="INTEGER"/> <!-- 评论用户ID -->
|
|
|
</resultMap>
|
|
|
|
|
|
<!-- 定义了一个SQL片段,用于在其他SQL语句中引用表名 -->
|
|
|
<sql id="tb">comment</sql>
|
|
|
|
|
|
<!-- 定义了一个SQL片段,用于在其他SQL语句中引用列名 -->
|
|
|
<sql id="Base_Column_List">
|
|
|
comment_id, comment_pid, comment_pname, comment_article_id, comment_author_name,
|
|
|
comment_author_email, comment_author_url, comment_author_avatar, comment_content, comment_agent,
|
|
|
comment_ip, comment_create_time, comment_role, comment_user_id
|
|
|
</sql>
|
|
|
|
|
|
<!-- 根据ID获取评论 -->
|
|
|
<select id="getCommentById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
|
|
|
select
|
|
|
<include refid="Base_Column_List"/>
|
|
|
from
|
|
|
<include refid="tb"/>
|
|
|
where comment_id = #{commentId,jdbcType=INTEGER}
|
|
|
</select>
|
|
|
|
|
|
<!-- 根据ID删除评论 -->
|
|
|
<delete id="deleteById" parameterType="java.lang.Integer">
|
|
|
delete from
|
|
|
<include refid="tb"/>
|
|
|
where comment_id = #{commentId,jdbcType=INTEGER}
|
|
|
</delete>
|
|
|
|
|
|
<!-- 根据用户ID删除评论 -->
|
|
|
<delete id="deleteByUserId">
|
|
|
delete from
|
|
|
<include refid="tb"/>
|
|
|
WHERE comment_user_id = #{userId}
|
|
|
</delete>
|
|
|
|
|
|
<!-- 根据文章ID删除评论 -->
|
|
|
<delete id="deleteByArticleId">
|
|
|
delete from
|
|
|
<include refid="tb"/>
|
|
|
WHERE comment_article_id = #{articleId}
|
|
|
</delete>
|
|
|
|
|
|
<!-- 插入一个新的评论 -->
|
|
|
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Comment" useGeneratedKeys="true"
|
|
|
keyProperty="commentId">
|
|
|
insert into
|
|
|
<include refid="tb"/>
|
|
|
(comment_pid, comment_pname, comment_article_id,
|
|
|
comment_author_name, comment_author_email,
|
|
|
comment_author_url, comment_author_avatar, comment_content, comment_agent,
|
|
|
comment_ip, comment_create_time, comment_role, comment_user_id)
|
|
|
values (#{commentPid,jdbcType=INTEGER}, #{commentPname,jdbcType=VARCHAR}, #{commentArticleId,jdbcType=INTEGER},
|
|
|
#{commentAuthorName,jdbcType=VARCHAR}, #{commentAuthorEmail,jdbcType=VARCHAR},
|
|
|
#{commentAuthorUrl,jdbcType=VARCHAR},#{commentAuthorAvatar}, #{commentContent,jdbcType=VARCHAR},
|
|
|
#{commentAgent,jdbcType=VARCHAR},
|
|
|
#{commentIp,jdbcType=VARCHAR}, #{commentCreateTime,jdbcType=TIMESTAMP}, #{commentRole,jdbcType=INTEGER},
|
|
|
#{commentUserId,jdbcType=INTEGER})
|
|
|
</insert>
|
|
|
|
|
|
<!-- 更新评论信息 -->
|
|
|
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
update
|
|
|
<include refid="tb"/>
|
|
|
<set>
|
|
|
<if test="commentPid != null">comment_pid = #{commentPid,jdbcType=INTEGER},</if>
|
|
|
<if test="commentPname != null">comment_pname = #{commentPname,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentArticleId != null">comment_article_id = #{commentArticleId,jdbcType=INTEGER},</if>
|
|
|
<if test="commentAuthorName != null">comment_author_name = #{commentAuthorName,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentAuthorEmail != null">comment_author_email = #{commentAuthorEmail,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentAuthorUrl != null">comment_author_url = #{commentAuthorUrl,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentContent != null">comment_content = #{commentContent,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentAgent != null">comment_agent = #{commentAgent,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentIp != null">comment_ip = #{commentIp,jdbcType=VARCHAR},</if>
|
|
|
<if test="commentCreateTime != null">comment_create_time = #{commentCreateTime,jdbcType=TIMESTAMP},</if>
|
|
|
<if test="commentAuthorAvatar != null">comment_author_avatar = #{commentAuthorAvatar},</if>
|
|
|
<if test="commentRole != null">comment_role = #{commentRole,jdbcType=INTEGER},</if>
|
|
|
<if test="commentUserId != null">comment_user_id = #{commentUserId,jdbcType=INTEGER},</if>
|
|
|
</set>
|
|
|
where comment_id = #{commentId,jdbcType=INTEGER}
|
|
|
</update>
|
|
|
<!-- 根据文章ID获取文章的所有评论 -->
|
|
|
<select id="listCommentByArticleId" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
SELECT
|
|
|
<include refid="Base_Column_List"/>
|
|
|
FROM
|
|
|
<include refid="tb"/>
|
|
|
WHERE
|
|
|
comment_article_id = #{id}
|
|
|
ORDER BY comment_id ASC
|
|
|
</select>
|
|
|
|
|
|
<!-- 获取评论列表,支持根据用户ID过滤 -->
|
|
|
<select id="listComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
SELECT
|
|
|
<include refid="Base_Column_List"/>
|
|
|
FROM
|
|
|
<include refid="tb"/>
|
|
|
<where>
|
|
|
<if test="userId != null">
|
|
|
comment_user_id = #{userId}
|
|
|
</if>
|
|
|
</where>
|
|
|
ORDER BY comment_id DESC
|
|
|
</select>
|
|
|
|
|
|
<!-- 获取接收到的评论,即根据一组文章ID获取对应的评论 -->
|
|
|
<select id="getReceiveComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
SELECT
|
|
|
<include refid="Base_Column_List"/>
|
|
|
FROM
|
|
|
<include refid="tb"/>
|
|
|
<where>
|
|
|
comment_article_id IN (
|
|
|
<foreach collection="list" item="item" separator=",">
|
|
|
#{item}
|
|
|
</foreach>
|
|
|
)
|
|
|
</where>
|
|
|
ORDER BY comment_id DESC
|
|
|
</select>
|
|
|
|
|
|
<!-- 统计总评论数 -->
|
|
|
<select id="countComment" parameterType="Integer" resultType="Integer">
|
|
|
SELECT count(*) FROM
|
|
|
<include refid="tb"/>
|
|
|
</select>
|
|
|
|
|
|
<!-- 获取最近评论,支持根据用户ID过滤 -->
|
|
|
<select id="listRecentComment" parameterType="Integer" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
SELECT
|
|
|
<include refid="Base_Column_List"/>
|
|
|
FROM
|
|
|
<include refid="tb"/>
|
|
|
<where>
|
|
|
<if test="userId != null">
|
|
|
comment_user_id = #{userId}
|
|
|
</if>
|
|
|
</where>
|
|
|
ORDER BY comment_id DESC
|
|
|
LIMIT #{limit}
|
|
|
</select>
|
|
|
|
|
|
<!-- 获取某个评论的子评论列表 -->
|
|
|
<select id="listChildComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
|
|
|
SELECT
|
|
|
<include refid="Base_Column_List"/>
|
|
|
FROM
|
|
|
<include refid="tb"/>
|
|
|
WHERE
|
|
|
comment_pid=#{id}
|
|
|
</select>
|
|
|
</mapper> |