900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统(功能包含前后台 登录 mark

SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统(功能包含前后台 登录 mark

时间:2019-10-06 13:23:23

相关推荐

SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统(功能包含前后台 登录 mark

博客目录

SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统实现功能截图系统功能使用技术代码完整源码

SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统

本系统是一个校园论坛管理系统,分为前后台,前台可以发帖留言,亮点是集成了mardown文档,可以有个很美观的帖子格式。后台管理员可以对用户、帖子、评论、分类等进行管理。

(文末查看完整源码)

实现功能截图

登录

帖子查看

帖子详情

markdown发帖

留言

后台首页

用户管理

分类管理

帖子管理

回复评论管理

通知管理

系统功能

本系统实现了以下功能:

1、登录

2、分类帖子查看

3、留言

4、发帖

5、用户管理

6、帖子管理

7、评论管理

8、留言管理

9、回复管理

10、分类管理

11、通知管理

使用技术

数据库:mysql

开发工具:Idea(Myeclispe、Eclipse也可以)

知识点:Spring+structs2+hibernate

项目结构

代码

java端

实体类

Comment.java

package com.forum.entity;import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import java.util.ArrayList;import java.util.Date;import java.util.List;@Data@AllArgsConstructor@NoArgsConstructorpublic class Comment {private Long id;private String username;private String email;private String content;//是否为用户评论private boolean userComment;//头像private String avatar;private Date createTime;private Long forumId;private Long parentCommentId; //父评论id,是為1// private String parentNickname;//回复评论private List<Comment> replyComments = new ArrayList<>();//是否是用户评论private Comment parentComment;private Forum forum;}

Forum.java

package com.forum.entity;import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import java.util.ArrayList;import java.util.Date;import java.util.List;@Data@AllArgsConstructor@NoArgsConstructorpublic class Forum {private Long id;private String title;private String content;private String avatars;// 原创转载private String flag;private Integer views;private boolean commentabled;private Date createTime;private Date updateTime;private Long userId;private String description;private int like;// private Admin admin;private User user;private List<Tag> tags = new ArrayList<>();private List<Comment> comments = new ArrayList<>();private String tagIds;public void init(){this.tagIds = tagsToIds(this.getTags());}//将tags集合转换为tagIds字符串形式:“1,2,3”,用于编辑博客时显示博客的tagprivate String tagsToIds(List<Tag> tags){if(!tags.isEmpty()){StringBuffer ids = new StringBuffer();boolean flag = false;for(Tag tag: tags){if(flag){ids.append(",");}else {flag = true;}ids.append(tag.getId());}return ids.toString();}else {return tagIds;}}}

CommentServiceImpl.java

package com.forum.service.impl;import com.forum.dao.ForumDao;import com.mentDao;import com.ment;import com.mentService;import org.springframework.beans.BeanUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.ArrayList;import java.util.Date;import java.util.List;@Servicepublic class CommentServiceImpl implements CommentService {@Autowiredprivate CommentDao commentDao;@Autowiredprivate ForumDao forumDao;@Overridepublic List<Comment> getCommentByForumId(Long forumId) {//查询父评论//没有父节点的默认为-1List<Comment> comments = commentDao.findByForumIdAndParentCommentNull(forumId, Long.parseLong("-1"));return comments;}@Override//接收回复的表单public int saveComment(Comment comment) {//获得父idLong parentCommentId = comment.getParentComment().getId();System.out.println("是否是父评论"+parentCommentId);comment.setAvatar("/aab1692cf70ed27d9ebcf0ca3e88d61d.jpg");//没有父级评论默认是-1if (parentCommentId != -1) {//有父级评论// comment.setParentComment(commentDao.findByParentCommentId(comment.getParentCommentId()));comment.setParentCommentId(parentCommentId);} else {//没有父级评论comment.setParentCommentId((long) 0);// comment.setParentComment(null);}comment.setCreateTime(new Date());return commentDao.saveComment(comment);}@Overridepublic List<Comment> getAllComment() {return commentDao.getAllComment();}@Overridepublic void delById(Integer id) {commentDao.delById(id);}/*** 循环每个父评论“1”*/// private List<Comment> oneComment(List<Comment> comments){// List<Comment> commentsView = new ArrayList<>();// for (Comment comment : comments) {// Comment comment1 = new Comment();// BeanUtils.copyProperties(comment,comment1);// commentsView.add(comment1);//// }// combineChildren(commentsView);// return commentsView;// }//// /**//* 存储帖子为1的对象集合//* @param comments//*/// private void combineChildren(List<Comment> comments) {// for (Comment comment : comments) {// List<Comment> replys1 = comment.getReplyComments();// for (Comment reply1 : replys1) {//recursively(reply1);// }// comment.setReplyComments(tempReplys);// tempReplys = new ArrayList<>();// }// }//private List<Comment> tempReplys =new ArrayList<>();//// /**//* 迭代的对象//* @param//*/// private void recursively(Comment comment) {// tempReplys.add(comment);// if (comment.getReplyComments().size()>0){// List<Comment> replys = comment.getReplyComments();// for (Comment reply : replys) {//tempReplys.add(reply);//if (reply.getReplyComments().size()>0){//recursively(reply);//}//// }// }// }}

ForumServiceImpl.java

package com.forum.service.impl;import com.forum.dao.ForumDao;import com.forum.entity.*;import com.forum.exception.NotFoundException;import com.forum.service.ForumService;import com.forum.service.TagService;import com.forum.utils.MarkdownUtils;//import com.forum.utils.RedisUtil;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.*;@Servicepublic class ForumServiceImpl implements ForumService {@AutowiredForumDao forumDao;@AutowiredTagService tagService;// @Autowired// RedisUtil redisUtil;private Boolean hasKey = false;@Overridepublic void updateView(Long id) {forumDao.updateView(id);}@Overridepublic Forum getForum(Long id) {return forumDao.getForum(id);}@Overridepublic Forum getDetailedForum(Long id) {Forum forum = forumDao.getDetailedForum(id);if (forum == null) {throw new NotFoundException("该帖子不存在");}String content = forum.getContent();forum.setContent(MarkdownUtils.markdownToHtmlExtensions(content)); //将Markdown格式转换成htmlreturn forum;}@Overridepublic List<Forum> getAllForum() {return forumDao.getAllForum();}@Overridepublic List<Forum> getByTypeId(Long typeId) {return forumDao.getByTypeId(typeId);}@Overridepublic List<Forum> getByTagId(Long tagId) {return forumDao.getByTagId(tagId);}@Overridepublic List<Forum> getIndexForum() {List<Forum> forums = forumDao.getIndexForum();// int startPage=(pageNum-1)*5;// List<Forum> forums= forumDao.getForumTadIds();// System.out.println(forums.size());// List<Tag> tags;// for (Forum forum : forums) {// tags=new ArrayList<>();// for (TagIds id : forum.getTagsId()) {//tags.add(tagService.getTagById(id.getTag_id()));// }// forum.setTags(tags);//// }return forums;}@Overridepublic List<Forum> getAllRecommendForum() {return forumDao.getAllRecommendForum();}@Overridepublic List<Forum> getSearchForum(String query) {return forumDao.getSearchForum(query);}@Overridepublic Map<String, List<Forum>> archiveForum() {List<String> years;Map<String, List<Forum>> map = new LinkedHashMap<>();years = forumDao.findGroupYear();Set<String> set = new HashSet<>(years); //set去掉重复的年份// 转回list进行排序years = new ArrayList<>(set);Collections.sort(years);Collections.reverse(years);// 遍历for (String year : years) {System.out.println(year);map.put(year, findForumAndTagsByYear(year));}return map;}/*根据查找文章的所有*/public List<Forum> findForumAndTagsByYear(String year) {List<Forum> forumAndTagIds = forumDao.findForumAndTagsByYear(year);// 将标签的id集合遍历查找出标签List<Tag> tags;for (Forum forumAndTagId : forumAndTagIds) {tags = new ArrayList<>();// System.out.println(tags.size());forumAndTagId.setTags(tags);}return forumAndTagIds;}@Overridepublic int countForum() {return forumDao.getAllForum().size();}@Overridepublic List<Forum> searchAllForum(Forum forum) {return forumDao.searchAllForum(forum);}/*** 排行榜信息** @return*/@Overridepublic List<RankForum> findForumByLank() {List<RankForum> rankForums = new ArrayList<>();rankForums = forumDao.findForumByRank();return rankForums;//// }else {// System.out.println("走REDIS---");// return (List<RankForum>) redisUtil.get("rank");//// }}@Overridepublic List<RankForum> getNewForum() {return forumDao.getNewForum();}// @Override// public Long getLike(Long id) {// return forumDao.getLike(id);// }// @Override// public void addLike(Long forumId, Long userId) {forumDao.addLike(forumId); forumDao.addForum_Like(forumId, userId);// System.out.println("执行插入Like_User");//// }// @Override// public int getLikeByUser(Long userId, Long forumId) {// return forumDao.getLikeByUser(userId, forumId);// }// @Override// public void cancelLike(Long forumId, Long userId) {// forumDao.cancelLike(forumId);// forumDao.removeForum_Like(forumId, userId);// }@Overridepublic int countView() {return forumDao.countView();}@Overridepublic void addLike(Long id) {forumDao.addLike(id);}@Override //新增帖子public int saveForum(Forum forum) {forum.setCreateTime(new Date());forum.setViews(0);// forum.setFlag("原创");//保存帖子forumDao.saveForum(forum);//保存帖子后才能获取自增的idLong id = forum.getId();//将标签的数据存到t_forums_tag表中List<Tag> tags = forum.getTags();ForumAndTag forumAndTag = null;for (Tag tag : tags) {//新增时无法获取自增的id,在mybatis里修改forumAndTag = new ForumAndTag(tag.getId(), id);forumDao.saveForumAndTag(forumAndTag);}return 1;}@Override //编辑帖子public int updateForum(Forum forum) {forum.setUpdateTime(new Date());//将标签的数据存到t_forums_tag表中List<Tag> tags = forum.getTags();ForumAndTag forumAndTag = null;for (Tag tag : tags) {forumAndTag = new ForumAndTag(tag.getId(), forum.getId());forumDao.saveForumAndTag(forumAndTag);}return forumDao.updateForum(forum);}@Overridepublic int deleteForum(Long id) {return forumDao.deleteForum(id);}}

controller层

CommentController.java

package com.forum.controller;import com.ment;import com.forum.entity.User;import com.forum.service.ForumService;import com.mentService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.PostMapping;import javax.servlet.http.HttpSession;@Controllerpublic class CommentController {@Autowiredprivate CommentService commentService;@Autowiredprivate ForumService forumService;// @Value("${comment.avatar}")private String avatar;@GetMapping("/comments/{forumId}") //展示public String getComments(@PathVariable Long forumId, Model model){model.addAttribute("comments", commentService.getCommentByForumId(forumId));model.addAttribute("forum", forumService.getDetailedForum(forumId));return "forum :: commentList";}@PostMapping("/comments") //提交public String postComment(Comment comment, HttpSession session){Long forumId = comment.getForum().getId();comment.setForum(forumService.getDetailedForum(forumId)); //绑定评论comment.setForumId(forumId);User user = (User) session.getAttribute("user");if (user != null){//用户存在comment.setAvatar(user.getAvatar());comment.setUserComment(true);}else {comment.setAvatar(avatar);}System.out.println(comment);String contents = comment.getContent();String arr[]={"垃圾","滚","混蛋","王八蛋","有病","美白","祛痘","祛斑","纯天然","换肤","去除皱纹","防脱发","生发","无毒","安全","瘦脸","助眠",};for (int i = 0; i < arr.length; i++) {contents= contents.replaceAll(arr[i],"*");System.out.println(contents);comment.setContent(contents);}commentService.saveComment(comment);return "redirect:/comments/" + forumId;}}

ForumController.java

package com.forum.controller.admin;import com.forum.entity.Forum;import com.forum.entity.User;import com.forum.service.ForumService;import com.forum.service.TagService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import org.springframework.web.servlet.mvc.support.RedirectAttributes;import javax.servlet.http.HttpSession;import java.util.List;@Controller@RequestMapping("/admin")public class ForumController {@Autowiredprivate ForumService forumService;@Autowiredprivate TagService tagService;public void setTypeAndTag(Model model) {model.addAttribute("tags", tagService.getAllTag());}@GetMapping("/forums") //后台显示帖子列表public String forums(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum, Model model){PageHelper.startPage(pagenum, 5);List<Forum> allForum = forumService.getAllForum();//得到分页结果对象PageInfo pageInfo = new PageInfo(allForum);model.addAttribute("pageInfo", pageInfo);setTypeAndTag(model); //查询类型和标签return "admin/forums";}@GetMapping("/forums/input") //去新增帖子页面public String toAddForum(Model model){model.addAttribute("forum", new Forum()); //返回一个forum对象给前端th:objectsetTypeAndTag(model);return "admin/forums-input";}@PostMapping("/forums") //新增public String addForum(Forum forum, HttpSession session, RedirectAttributes attributes){//设置user属性forum.setUser((User) session.getAttribute("admin"));//设置用户idforum.setUserId(forum.getUser().getId());// //设置forum的type//给forum中的List<Tag>赋值forum.setTags(tagService.getTagByString(forum.getTagIds()));forumService.saveForum(forum);attributes.addFlashAttribute("msg", "新增成功");return "redirect:/admin/forums";}@GetMapping("/forums/{id}/edit") //去编辑帖子页面public String toEditForum(@PathVariable Long id, Model model){Forum forum = forumService.getForum(id);forum.init(); //将tags集合转换为tagIds字符串model.addAttribute("forum", forum);//返回一个forum对象给前端th:objectsetTypeAndTag(model);return "admin/forums-edit";}@PostMapping("/forums/edit") //编辑public String editForum(Forum forum, HttpSession session, RedirectAttributes attributes){//设置user属性forum.setUser((User) session.getAttribute("admin"));//设置用户idforum.setUserId(forum.getUser().getId());// //设置forum的type//给forum中的List<Tag>赋值forum.setTags(tagService.getTagByString(forum.getTagIds()));System.out.println(forum);forumService.updateForum(forum);attributes.addFlashAttribute("msg", "编辑成功");return "redirect:/admin/forums";}@GetMapping("/forums/{id}/delete")public String deleteForums(@PathVariable Long id, RedirectAttributes attributes){forumService.deleteForum(id);attributes.addFlashAttribute("msg", "删除成功");return "redirect:/admin/forums";}@PostMapping("/forums/search") //按条件查询帖子public String searchForums(Forum forum, @RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum, Model model){PageHelper.startPage(pagenum, 5);List<Forum> allForum = forumService.searchAllForum(forum);//得到分页结果对象PageInfo pageInfo = new PageInfo(allForum);model.addAttribute("pageInfo", pageInfo);model.addAttribute("message", "查询成功");setTypeAndTag(model);return "forums";}}

完整源码

觉得有用,记得一键三连哦!

SpringBoot+Mybatis+Maven+Mysql实现的校园论坛管理系统(功能包含前后台 登录 markdown发帖 留言 分类帖子查看 用户管理 帖子管理 回复管理 评论管理 留言管理等)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。