springboot个人博客系统之评论模块

个人博客系统开发简要分为五大模块

  1. 首页

  2. 登录功能

  3. 评论管理

  4. 文章管理

  5. 邮件管理

一个完善的博客系统,前端页面可以展示、发布评论,评论用户可以互相回复、后台可以管理评论内容。由于篇幅有限,本项目的文章评论会实现前端评论展示、发布评论等功能。

本期给大家介绍的是评论管理模块

1.业务处理层实现

实现查看文章详情时,评论类Comments 操作数据库的Mapper 接口文件已经编写好了,这里直接从Service业务层处理评论管理的相关业务。


(1)编写Service层接口方法


在评论业务接口文件ICommentService中编写一个发布文章评论的方法,示例代码如下。

  // 用户发表评论
      public void pushComment(Comment comment) {
  
(2)编写Service 层接口实现类方法

在评论业务层接口实现类CommentServicelmpl中实现新增的评论发布方法,示例代码如下。

  // 用户发表评论
    @Override
    public void pushComment(Comment comment) {
        commentMapper.pushComment(comment);
        // 更新文章评论数据量
        Statistic statistic = statisticMapper.selectStatisticWithArticleId(comment.getArticleId());
        statistic.setCommentsNum(statistic.getCommentsNum() + 1);
        statisticMapper.updateArticleCommentsWithId(statistic);
    }

上述代码中,在CommentServicelmpl的评论发布方法中,先进行了评论数据发布操作,然
周用统计类接口文件statisticMapper的相关方法对文章评论信息数量进行了统计更新。


2.请求处理层实现


2.1在com.itheima.web.client包下创建一个用户评论管理的控制类CommentController,并编
相应的请求控制方法,内容如下所示。
package com.itheima.web.client;

import com.itheima.model.ResponseData.ArticleResponseData;
import com.itheima.model.domain.Comment;
import com.itheima.service.ICommentService;
import com.itheima.utils.MyUtils;
import com.vdurmont.emoji.EmojiParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


/**
 * @version 1.0
 * @Author LDX
 * @Date 2023/11/3 17:02
 * @注释
 */

@Controller
@RequestMapping("/comments")
public class CommentController {
    private static final Logger logger = LoggerFactory.getLogger(CommentController.class);

    @Autowired
    private ICommentService commentServcieImpl;

    // 发表评论操作
    @PostMapping(value = "/publish")
    @ResponseBody
    public ArticleResponseData publishComment(HttpServletRequest request, @RequestParam Integer aid, @RequestParam String text) {
        // 去除js脚本
        text = MyU
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值