package com.sdxb.blog.controller;
import com.sdxb.blog.dto.CommentCreateDto;
import com.sdxb.blog.dto.CommentDto;
import com.sdxb.blog.dto.ResultDto;
import com.sdxb.blog.entity.Comment;
import com.sdxb.blog.entity.Notification;
import com.sdxb.blog.entity.Question;
import com.sdxb.blog.entity.User;
import com.sdxb.blog.enums.NotificationStatusEnum;
import com.sdxb.blog.enums.notificationEnum;
import com.sdxb.blog.mapper.CommentMapper;
import com.sdxb.blog.mapper.NotificationMapper;
import com.sdxb.blog.mapper.QuestionMapper;
import com.sdxb.blog.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
//回复功能
@Controller
public class CommentController {
@Resource
private UserMapper userMapper;
@Resource
private CommentMapper commentMapper;
@Resource
private QuestionMapper questionMapper;
@Resource
private NotificationMapper notificationMapper;
@ResponseBody
@RequestMapping(value = "/comment",method = RequestMethod.POST)
public Object post(@RequestBody CommentCreateDto commentCreateDto,
HttpServletRequest request){
//把User写进session
Cookie[] cookies = request.getCookies();
if (cookies == null) {
return "login";
}
User user = null;
for (Cookie cookie : cookies) {
if (cookie.getName().equals("token")) {
String token = cookie.getValue();
user = userMapper.findBytoken(token);
if (user != null) {
request.getSession().setAttribute("user", user);
//获取未读的消息数量
int unreadnum=notificationMapper.getunreadcount(user.getId());
request.getSession().setAttribute("unreadnum",unreadnum);
}
break;
}
}
//把评论插入数据库
Comment comment=new Comment();
comment.setParent_id(commentCreateDto.getParent_id());
comment.setContent(commentCreateDto.getContent());
comment.setType(commentCreateDto.getType());
comment.setCreatetime(System.currentTimeMillis());
comment.setCommentor(user.getId());
commentMapper.insert(comment);
if (commentCreateDto.getType()==2){
//把回复评论的通知插入数据库
Notification notification=new Notification();
notification.setNotifier(comment.getCommentor());
Comment comment2=commentMapper.getparentbyid(commentCreateDto.getParent_id());
notification.setReceiver(comment2.getCommentor());
notification.setOuterid(commentCreateDto.getParent_id());
notification.setType(notificationEnum.NOTIFICATION_COMMENT.getType());
notification.setCreatetime(System.currentTimeMillis());
notification.setStatus(NotificationStatusEnum.UNREAD.getStatus());
notificationMapper.insert(notification);
//增加评论数
commentMapper.updatecommentcount(commentCreateDto.getParent_id());
}else {
//把回复问题的通知插入数据库
Question question=questionMapper.getbyId(commentCreateDto.getParent_id());
Notification notification=new Notification();
notification.setNotifier(user.getId());
notification.setReceiver(question.getCreateid());
notification.setOuterid(commentCreateDto.getParent_id());
notification.setType(notificationEnum.NOTIFICATION_QUESTION.getType());
notification.setCreatetime(System.currentTimeMillis());
notification.setStatus(NotificationStatusEnum.UNREAD.getStatus());
notificationMapper.insert(notification);
//增加问题回复量
questionMapper.updatecomment(commentCreateDto.getParent_id());
}
ResultDto resultDto=new ResultDto();
return resultDto.success();
}
@ResponseBody
@RequestMapping(value = "/comment/{id}",method = RequestMethod.GET)
public ResultDto<List<CommentDto>> comments(@PathVariable(name = "id") int id,
HttpServletRequest request){
//查找type=2,即是回复评论的评论
List<Comment> comments = commentMapper.getCommentByid(id,2);
List<CommentDto> commentDto=new ArrayList<>();
//找到User
Cookie[] cookies = request.getCookies();
User user = null;
for (Cookie cookie : cookies) {
if (cookie.getName().equals("token")) {
String token = cookie.getValue();
user = userMapper.findBytoken(token);
break;
}
}
//把二级评论和对应的User写进每个CommentDto集合中
for (Comment comment:comments){
CommentDto dto=new CommentDto();
BeanUtils.copyProperties(comment,dto);
dto.setUser(user);
commentDto.add(dto);
}
ResultDto resultDto=new ResultDto();
//返回数据给前端
return resultDto.success(commentDto);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot和BootStrap的论坛博客网站+源代码+文档说明+数据库sql
共450个文件
js:182个
html:106个
css:55个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 70 浏览量
2023-11-28
16:13:48
上传
评论
收藏 6.87MB ZIP 举报
温馨提示
## thymeleaf官方文档 ``` https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html ``` ## BootStrap官方文档 ``` https://v3.bootcss.com/components/ ``` ## Editor.md官网 ``` http://editor.md.ipandao.com/ ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot和BootStrap的论坛博客网站+源代码+文档说明+数据库sql (450个子文件)
AUTHORS 6KB
mvnw.cmd 6KB
bootstrap.css 143KB
bootstrap.min.css 118KB
editormd.css 76KB
editormd.preview.css 55KB
ambiance.css 26KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
codemirror.css 8KB
codemirror.min.css 5KB
mdn-like.css 5KB
solarized.css 5KB
merge.css 3KB
lint.css 3KB
xq-dark.css 3KB
lesser-dark.css 2KB
pastel-on-dark.css 2KB
xq-light.css 2KB
tomorrow-night-eighties.css 2KB
erlang-dark.css 2KB
zenburn.css 2KB
twilight.css 2KB
midnight.css 2KB
vibrant-ink.css 2KB
mbo.css 2KB
base16-dark.css 2KB
base16-light.css 2KB
tern.css 2KB
3024-night.css 2KB
paraiso-dark.css 2KB
paraiso-light.css 2KB
tomorrow-night-bright.css 2KB
3024-day.css 2KB
blackboard.css 2KB
colorforth.css 2KB
the-matrix.css 2KB
night.css 2KB
rubyblue.css 2KB
monokai.css 1KB
cobalt.css 1KB
simplescrollbars.css 1KB
eclipse.css 1KB
index.css 1KB
signin.css 952B
neo.css 932B
elegant.css 768B
neat.css 693B
show-hint.css 662B
dialog.css 502B
tiki.css 440B
foldgutter.css 435B
publish.css 363B
tiddlywiki.css 220B
matchesonscrollbar.css 188B
fullscreen.css 116B
ambiance-mobile.css 103B
fontawesome-webfont.eot 59KB
glyphicons-halflings-regular.eot 20KB
editormd-logo.eot 1KB
[email protected] 21KB
[email protected] 16KB
loading.gif 8KB
.gitignore 333B
scala.html 28KB
index.html 22KB
index.html 17KB
index.html 13KB
index.html 13KB
index.html 11KB
index.html 10KB
index.html 9KB
index.html 8KB
question.html 8KB
index.html 8KB
personal.html 7KB
index.html 7KB
index.html 7KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 5KB
index.html 5KB
index.html 4KB
publish.html 4KB
index.html 4KB
index.html 4KB
index.html 4KB
index.html 4KB
index.html 4KB
index.html 4KB
index.html 4KB
less.html 4KB
index.html 4KB
index.html 3KB
index.html 3KB
index.html 3KB
共 450 条
- 1
- 2
- 3
- 4
- 5
资源评论
奋斗奋斗再奋斗的ajie
- 粉丝: 230
- 资源: 2166
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功