基于SSM实现个人博客系统
项目编号:BS-PT-005
该博客是基于SSM实现的一个个人博客系统,适合初学SSM和个人博客制作的同学学习。 主要涉及技术包括的包括 Maven、Spring、SpringMVC、MyBatis、Redis、JSP等。 前端采用Layui框架
开发工具:IDEA
JDK: JDK1.8
TOMCAT: Tomcat8
DB: MySql5
--------------------------------------------------------------------------------------------------------------------
前端页面:
用户在博客系统前端可以实现博客查看,留言,评论,打赏等功能。



博客详情:

后台管理界面:


文章管理模块:
包含文件音、文章分类、文章标签的相关管理操作。

页面管理模块:
可以自定义页面,在前端进行相应的展示。

友情链接管理模块:

公告管理模块:

评论管理模块:

用户管理模块:

系统管理模块:
包含系统菜单管理和系统信息设置



本项目后整体基于SSM框架实现,前端采用Layui框架,系统功能完整,页面美观大方,交互性好,运行无BUG,比较适合毕业设计项目的应用。
部分核心代码实现:
package com.liuyanzhao.ssm.blog.controller.home;import com.github.pagehelper.PageInfo;import com.liuyanzhao.ssm.blog.entity.Link;import com.liuyanzhao.ssm.blog.enums.ArticleStatus;import com.liuyanzhao.ssm.blog.enums.LinkStatus;import com.liuyanzhao.ssm.blog.enums.NoticeStatus;import com.liuyanzhao.ssm.blog.entity.*;import com.liuyanzhao.ssm.blog.service.*;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import java.util.HashMap;import java.util.List;/**
* 用户的controller
*
* @author znz
* @date 2022/1/1
*/public class IndexController {
private ArticleService articleService;
private LinkService linkService;
private NoticeService noticeService;
private TagService tagService;
private CommentService commentService;
public String index( {
HashMap<String, Object> criteria = Integer pageIndex, Integer pageSize, Model model)new HashMap<>(1);
criteria.put("status", ArticleStatus.PUBLISH.getValue()); //文章列表
PageInfo<Article> articleList = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articleList); //公告
List<Notice> noticeList = noticeService.listNotice(NoticeStatus.NORMAL.getValue());
model.addAttribute("noticeList", noticeList); //友情链接
List<Link> linkList = linkService.listLink(LinkStatus.NORMAL.getValue());
model.addAttribute("linkList", linkList); //侧边栏显示
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList); //最新评论
List<Comment> recentCommentList = commentService.listRecentComment(10);
model.addAttribute("recentCommentList", recentCommentList);
model.addAttribute("pageUrlPrefix", "/article?pageIndex"); return "Home/index";
}
public String search( { String keywords, Integer pageIndex, Integer pageSize, Model model)//文章列表
HashMap<String, Object> criteria = new HashMap<>(2);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
criteria.put("keywords", keywords);
PageInfo<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo); //侧边栏显示
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList); //获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList); //获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList); //最新评论
List<Comment> recentCommentList = commentService.listRecentComment(10);
model.addAttribute("recentCommentList", recentCommentList);
model.addAttribute("pageUrlPrefix", "/search?pageIndex"); return "Home/Page/search";
}
public String NotFound( {
model.addAttribute( String message, Model model)"message", message); return "Home/Error/404";
}
public String ServerError( {
model.addAttribute( String message, Model model)"message", message); return "Home/Error/500";
}
}
package com.liuyanzhao.ssm.blog.controller.home;import cn.hutool.http.HtmlUtil;import com.liuyanzhao.ssm.blog.dto.JsonResult;import com.liuyanzhao.ssm.blog.entity.Article;import com.liuyanzhao.ssm.blog.entity.Comment;import com.liuyanzhao.ssm.blog.enums.ArticleStatus;import com.liuyanzhao.ssm.blog.enums.Role;import com.liuyanzhao.ssm.blog.service.ArticleService;import com.liuyanzhao.ssm.blog.service.CommentService;import com.liuyanzhao.ssm.blog.util.MyUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest;import java.util.Date;/**
* @author znz
* @date 2021/9/10
*/public class CommentController {
private CommentService commentService;
private ArticleService articleService; /**
* '添加评论
*
* @param request
* @param comment
*/
public JsonResult insertComment(HttpServletRequest request, Comment comment) { //添加评论
comment.setCommentCreateTime(new Date());
comment.setCommentIp(MyUtils.getIpAddr(request)); if (request.getSession().getAttribute("user") != null) {
comment.setCommentRole(Role.ADMIN.getValue());
} else {
comment.setCommentRole(Role.VISITOR.getValue());
}
comment.setCommentAuthorAvatar(MyUtils.getGravatar(comment.getCommentAuthorEmail())); //过滤字符,防止XSS攻击
comment.setCommentContent(HtmlUtil.escape(comment.getCommentContent()));
comment.setCommentAuthorName(HtmlUtil.escape(comment.getCommentAuthorName()));
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()));
comment.setCommentAuthorUrl(HtmlUtil.escape(comment.getCommentAuthorUrl())); try {
commentService.insertComment(comment); //更新文章的评论数
Article article = articleService.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), comment.getCommentArticleId());
articleService.updateCommentCount(article.getArticleId());
} catch (Exception e) {
e.printStackTrace(); return new JsonResult().fail();
} return new JsonResult().ok();
}
}
package com.liuyanzhao.ssm.blog.controller.home;import com.github.pagehelper.PageInfo;import com.liuyanzhao.ssm.blog.entity.Article;import com.liuyanzhao.ssm.blog.entity.Tag;import com.liuyanzhao.ssm.blog.enums.ArticleStatus;import com.liuyanzhao.ssm.blog.service.ArticleService;import com.liuyanzhao.ssm.blog.service.TagService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import java.util.HashMap;import java.util.List;/**
* @author znz
* @date 2021/9/2
*/public class TagController {
private TagService tagService;
private ArticleService articleService; /**
* 根据标签查询文章
*
* @param tagId 标签ID
* @return 模板
*/
public String getArticleListByTag( { Integer tagId, Integer pageIndex, Integer pageSize,
Model model)//该标签信息
Tag tag = tagService.getTagById(tagId); if (tag == null) { return "redirect:/404";
}
model.addAttribute("tag", tag); //文章列表
HashMap<String, Object> criteria = new HashMap<>(2);
criteria.put("tagId", tagId);
criteria.put("status", ArticleStatus.PUBLISH.getValue());
PageInfo<Article> articlePageInfo = articleService.pageArticle(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", articlePageInfo); //侧边栏
//标签列表显示
List<Tag> allTagList = tagService.listTag();
model.addAttribute("allTagList", allTagList); //获得随机文章
List<Article> randomArticleList = articleService.listRandomArticle(8);
model.addAttribute("randomArticleList", randomArticleList); //获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList);
model.addAttribute("pageUrlPrefix", "/tag?pageIndex"); return "Home/Page/articleListByTag";
}
}
package com.liuyanzhao.ssm.blog.controller.home;import com.liuyanzhao.ssm.blog.entity.Article;import com.liuyanzhao.ssm.blog.entity.Category;import com.liuyanzhao.ssm.blog.entity.Page;import com.liuyanzhao.ssm.blog.entity.Tag;import com.liuyanzhao.ssm.blog.service.ArticleService;import com.liuyanzhao.ssm.blog.service.CategoryService;import com.liuyanzhao.ssm.blog.service.PageService;import com.liuyanzhao.ssm.blog.service.TagService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import java.util.List;/**
* @author znz
* @date 2021/9/7
*/public class PageController {
private PageService pageService;
private ArticleService articleService;
private CategoryService categoryService;
private TagService tagService; /**
* 页面详情页面
*
* @param key
* @return
*/
public String pageDetail( { String key, Model model)Page page = pageService.getPageByKey(1, key); if (page == null) { return "redirect:/404";
}
model.addAttribute("page", page); //侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList); return "Home/Page/page";
} /**
* 文章归档页面显示
*
* @return
*/
public String articleFile(Model model) {
List<Article> articleList = articleService.listAllNotWithContent();
model.addAttribute("articleList", articleList); //侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(10);
model.addAttribute("mostCommentArticleList", mostCommentArticleList); return "Home/Page/articleFile";
} /**
* 站点地图显示
*
* @return
*/
public String siteMap(Model model) { //文章显示
List<Article> articleList = articleService.listAllNotWithContent();
model.addAttribute("articleList", articleList); //分类显示
List<Category> categoryList = categoryService.listCategory();
model.addAttribute("categoryList", categoryList); //标签显示
List<Tag> tagList = tagService.listTag();
model.addAttribute("tagList", tagList); //侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(10);
model.addAttribute("mostCommentArticleList", mostCommentArticleList); return "Home/Page/siteMap";
} /**
* 留言板
*
* @return
*/
public String message(Model model) { //侧边栏显示
//获得热评文章
List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8);
model.addAttribute("mostCommentArticleList", mostCommentArticleList); return "Home/Page/message";
}
}