dao层修改 单元测试

This commit is contained in:
禾几海
2020-05-25 13:50:11 +08:00
parent 190e1624ca
commit 9185ff8f58
3 changed files with 210 additions and 72 deletions

View File

@@ -8,8 +8,8 @@ import java.util.List;
/**
* @Author: 小海
* @Date 2019/06/30 16:19
* @Description
* @Date: 2019/06/30 16:19
* @Description:
*/
@Mapper
@Repository
@@ -18,11 +18,9 @@ public interface CommentMapper {
int updateContent(String content, long id);
int updateResponder(String responder, long id);
int delete(long id);
int deleteByArticleId(long articleId);
int deleteByPagePath(String pagePath);
boolean existsById(long id);
@@ -30,19 +28,13 @@ public interface CommentMapper {
Comment getLastestComment();
List<Comment> findAllByAuthorIDAndType(long id, boolean isComment);
List<Comment> findAllByFromUser(long id);
List<Comment> findAllByPId(long pid);
List<Comment> findAllByPid(long pid);
List<Comment> findAllByArticleID(long articleId);
List<Comment> findAllByPagePath(String pagePath);
List<Comment> findAllByArticleIDAndPId(long articleID, long pid);
List<Comment> findAllByPagePathAndPid(String pagePath, long pid);
List<Comment> findCommentsByTypeAndPId(boolean isComment, long pid);
List<Comment> findAllByPId(int pid);
List<Comment> findAllByType(boolean isComment);
long countByType(boolean isComment);
long countByPagePath(String pagePath);
}

View File

@@ -3,21 +3,44 @@
<mapper namespace="cn.celess.blog.mapper.CommentMapper">
<resultMap id="commentResultMap" type="cn.celess.blog.entity.Comment">
<id column="co_id" property="id"/>
<result column="co_article_id" property="articleID"/>
<result column="is_comment" property="type"/>
<result column="author_id" property="authorID"/>
<result column="co_page_path" property="pagePath"/>
<result column="co_status" property="status"/>
<result column="co_content" property="content"/>
<result column="co_date" property="date"/>
<result column="co_pid" property="pid"/>
<result column="co_response_id" property="responseId"/>
<result column="co_from_author_id" property="fromUser.id"/>
<result column="co_to_author_id" property="toUser.id"/>
<result column="is_delete" property="delete"/>
</resultMap>
<insert id="insert">
insert into comment (co_article_id, is_comment, author_id, co_content, co_date, co_pid)
VALUES (#{articleID}, #{type}, #{authorID}, #{content}, #{date}, #{pid})
<selectKey resultType="java.lang.Long" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
<resultMap id="commentViewResultMap" type="cn.celess.blog.entity.Comment">
<id column="commentId" property="id"/>
<result column="pagePath" property="pagePath"/>
<result column="status" property="status"/>
<result column="content" property="content"/>
<result column="date" property="date"/>
<result column="pid" property="pid"/>
<result column="fromAuthorId" property="fromUser.id"/>
<result column="toAuthorId" property="toUser.id"/>
<result column="isDelete" property="delete"/>
<association property="fromUser" column="fromAuthorId" javaType="cn.celess.blog.entity.User">
<id column="fromAuthorId" property="id"/>
<result column="fromAuthorEmail" property="email"/>
<result column="fromAuthorDisplayName" property="displayName"/>
<result column="fromAuthorAvatar" property="avatarImgUrl"/>
</association>
<association property="toUser" column="toAuthorId" javaType="cn.celess.blog.entity.User">
<id column="toAuthorId" property="id"/>
<result column="toAuthorEmail" property="email"/>
<result column="toAuthorDisplayName" property="displayName"/>
<result column="toAuthorAvatar" property="avatarImgUrl"/>
</association>
</resultMap>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into comment (co_page_path, co_content, co_date, co_pid, co_from_author_id, co_to_author_id, is_delete)
VALUES (#{pagePath}, #{content}, now(), #{pid}, #{fromUser.id}, #{toUser.id}, false)
</insert>
<update id="updateContent">
@@ -26,71 +49,62 @@
where co_id = #{id}
</update>
<update id="updateResponder">
<update id="delete">
update comment
set co_response_id =#{responder}
set is_delete = true
where co_id = #{id}
</update>
<delete id="delete">
delete
from comment
where co_id = #{id}
</delete>
<delete id="deleteByArticleId">
delete
from comment
where co_article_id = #{articleId}
</delete>
<update id="deleteByPagePath">
update comment
set is_delete = true
where co_page_path = #{path}
</update>
<select id="existsById" resultType="java.lang.Boolean">
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
</select>
<select id="findCommentById" resultMap="commentResultMap">
<select id="findCommentById" resultMap="commentViewResultMap">
select *
from comment
where co_id = #{id}
from commentView
where commentId = #{id}
</select>
<select id="findAllByAuthorIDAndType" resultMap="commentResultMap">
<select id="findAllByFromUser" resultMap="commentViewResultMap">
select *
from comment
where author_id = #{id}
and is_comment = #{isComment}
from commentView
where fromAuthorId = #{id}
</select>
<select id="findAllByPId" resultMap="commentResultMap">
<select id="findAllByPid" resultMap="commentViewResultMap">
select *
from comment
where co_pid = #{pid}
from commentView
where pid = #{pid}
</select>
<select id="findAllByArticleID" resultMap="commentResultMap">
<select id="findAllByPagePath" resultMap="commentViewResultMap">
select *
from comment
where co_article_id = #{articleId}
from commentView
where pagePath = #{pagePath}
</select>
<select id="findAllByArticleIDAndPId" resultMap="commentResultMap">
<select id="findAllByPagePathAndPid" resultMap="commentViewResultMap">
select *
from comment
where co_article_id = #{articleID}
and co_pid = #{pid}
from commentView
where pagePath = #{pagePath}
and pid = #{pid}
</select>
<select id="findCommentsByTypeAndPId" resultMap="commentResultMap">
select *
from comment
where is_comment = #{isComment}
and co_pid = #{pid}
</select>
<select id="findAllByType" resultMap="commentResultMap">
select *
from comment
where is_comment = #{isComment}
</select>
<select id="countByType" resultType="java.lang.Long">
<select id="countByPagePath" resultType="java.lang.Long">
select count(*)
from comment
where is_comment = #{isComment}
from commentView
where pagePath = #{pagePath}
</select>
<select id="getLastestComment" resultMap="commentResultMap">
<select id="getLastestComment" resultMap="commentViewResultMap">
select *
from comment
order by co_id desc
from commentView
order by commentId desc
limit 1
</select>