-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
CommentMapper.xml
executable file
·125 lines (109 loc) · 5.82 KB
/
CommentMapper.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?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.liuyanzhao.ssm.blog.mapper.CommentMapper">
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Comment">
<id column="comment_id" property="commentId" jdbcType="INTEGER"/>
<result column="comment_pid" property="commentPid" jdbcType="INTEGER"/>
<result column="comment_pname" property="commentPname" jdbcType="VARCHAR"/>
<result column="comment_article_id" property="commentArticleId" jdbcType="INTEGER"/>
<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"/>
<result column="comment_create_time" property="commentCreateTime" jdbcType="TIMESTAMP"/>
<result column="comment_role" property="commentRole" jdbcType="INTEGER"/>
</resultMap>
<sql id="tb">comment</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
</sql>
<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>
<delete id="deleteById" parameterType="java.lang.Integer">
delete from
<include refid="tb"/>
where comment_id = #{commentId,jdbcType=INTEGER}
</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)
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})
</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>
</set>
where comment_id = #{commentId,jdbcType=INTEGER}
</update>
<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>
<!--获取评论列表-->
<select id="listComment" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
ORDER BY comment_id DESC
</select>
<!--统计评论数-->
<select id="countComment" parameterType="Integer" resultType="Integer">
SELECT count(*) FROM
<include refid="tb"/>
</select>
<!--获得最近评论,访客的评论-->
<select id="listRecentComment" parameterType="Integer" resultType="com.liuyanzhao.ssm.blog.entity.Comment">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="tb"/>
WHERE comment_role = 0
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>