项目编号: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 */ @Controller public class IndexController { @Autowired private ArticleService articleService; @Autowired private LinkService linkService; @Autowired private NoticeService noticeService; @Autowired private TagService tagService; @Autowired private CommentService commentService; @RequestMapping(value = {"/", "/article"}) public String index(@RequestParam(required = false, defaultValue = "1") Integer pageIndex, @RequestParam(required = false, defaultValue = "10") Integer pageSize, Model model) { HashMap<String, Object> criteria = 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"; } @RequestMapping(value = "/search") public String search( @RequestParam("keywords") String keywords, @RequestParam(required = false, defaultValue = "1") Integer pageIndex, @RequestParam(required = false, defaultValue = "10") 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"; } @RequestMapping("/404") public String NotFound(@RequestParam(required = false) String message, Model model) { model.addAttribute("message", message); return "Home/Error/404"; } @RequestMapping("/500") public String ServerError(@RequestParam(required = false) String message, Model model) { model.addAttribute("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 */ @Controller @RestController public class CommentController { @Autowired private CommentService commentService; @Autowired private ArticleService articleService; /** * '添加评论 * * @param request * @param comment */ @RequestMapping(value = "/comment", method = {RequestMethod.POST}) 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 */ @Controller public class TagController { @Autowired private TagService tagService; @Autowired private ArticleService articleService; /** * 根据标签查询文章 * * @param tagId 标签ID * @return 模板 */ @RequestMapping("/tag/{tagId}") public String getArticleListByTag(@PathVariable("tagId") Integer tagId, @RequestParam(required = false, defaultValue = "1") Integer pageIndex, @RequestParam(required = false, defaultValue = "10") 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 */ @Controller public class PageController { @Autowired private PageService pageService; @Autowired private ArticleService articleService; @Autowired private CategoryService categoryService; @Autowired private TagService tagService; /** * 页面详情页面 * * @param key * @return */ @RequestMapping(value = "/{key}") public String pageDetail(@PathVariable("key") 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 */ @RequestMapping(value = "/articleFile") 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 */ @RequestMapping(value = "/map") 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 */ @RequestMapping(value = "/message") public String message(Model model) { //侧边栏显示 //获得热评文章 List<Article> mostCommentArticleList = articleService.listArticleByCommentCount(8); model.addAttribute("mostCommentArticleList", mostCommentArticleList); return "Home/Page/message"; } }