添加评论
数据层
增加评论数据
修改帖子的评论数量
在接口定义CommentMapper
//添加评论
int insertComment(Comment comment);
DiscussPostMapper
//添加评论
int updateCommentCount(int id, int commentCount);
业务层
处理添加评论的业务
先增加评论,再更新帖子的评论数量
Comment-mapper.xml
<!-- 添加评论-->
<insert id="insertComment" parameterType="Comment">
insert into comment(<include refid="insertFields"></include>)
values(#{userId},#{entityType},#{entityId},#{targetId},#{content},#{status},#{createTime})
</insert>
定义接口CommunityConstant
/**
* 实体类型: 帖子
*/
int ENTITY_TYPE_POST = 1;
/**
* 实体类型: 评论
*/
int ENTITY_TYPE_COMMENT = 2;
CommentService
表现层
处理添加评论数据的请求
设置添加评论的表单
CommentController
//添加评论
测试结果