Java项目:SSM个人博客网站管理系统
创始人
2024-03-20 05:18:13

作者主页:源码空间站2022

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目包含管理员与游客两种角色;

管理员角色包含以下功能:

发表文章,查看文章,类别管理,添加类别,个人信息管理,评论管理,评论审核等功能。

游客角色包含以下功能:
首页,博客详情,文章分类,评论等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 

5.数据库:MySql 5.7版本;

6.是否Maven项目:是;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:JSP+CSS+JavaScript+bootstrap+jquery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入localhost:8080/personal_blog 登录

运行截图

游客角色

管理员角色

 

相关代码

BlogAdminController

package com.june.web.controller.admin;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;import com.june.lucene.BlogIndex;
import com.june.model.Blog;
import com.june.model.BlogType;
import com.june.model.PageBean;
import com.june.service.BlogService;
import com.june.service.BlogTypeService;
import com.june.service.CommentService;
import com.june.util.Constants;
import com.june.util.DateUtils;
import com.june.util.PageUtils;
import com.june.util.StringUtils;import lombok.extern.slf4j.Slf4j;/*** 博客Controller*/
@Controller
@RequestMapping("/blog")
public @Slf4j class BlogAdminController {@Resourceprivate BlogService blogService;@Resourceprivate BlogTypeService blogTypeService;@Resourceprivate CommentService commentService;@Resourceprivate BlogIndex blogIndex;@RequestMapping("/list")public String list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = Constants.DEFAULT_PAGE_SIZE - 1 + "") Integer pageSize,String firstDate, String secondDate, Integer typeId, String title, Model model,HttpServletRequest request) {Map map = new HashMap<>(6);map.put("typeId", typeId);map.put("title", title);map.put("firstDate", firstDate);map.put("secondDate", secondDate);int totalCount = blogService.getCount(map);PageBean pageBean = new PageBean(totalCount, page, pageSize);map.put("start", pageBean.getStart());map.put("size", pageSize);model.addAttribute("pagination", pageBean);List blogTypeList = blogTypeService.getTypeList();model.addAttribute("blogTypeList",blogTypeList);StringBuilder param = new StringBuilder(); // 分页查询参数param.append(StringUtils.isEmpty(title) ? "" : "title=" + title);param.append(StringUtils.isEmpty(firstDate) ? "" : "&firstDate=" + firstDate);param.append(StringUtils.isEmpty(secondDate) ? "" : "&secondDate=" + secondDate);param.append(typeId == null ? "" : "&typeId=" + typeId);String pageCode = PageUtils.genPagination(request.getContextPath() + "/blog/list.do",pageBean, param.toString());model.addAttribute("pageCode", pageCode);model.addAttribute("entry", map);model.addAttribute("blogList", blogService.getBlogList(map));return "blog/list";}@RequestMapping("/toAdd")public String toAdd(Model model) {model.addAttribute("blogTypeList", blogTypeService.getTypeList());return "blog/add";}@RequestMapping("/toUpdate")public String toUpdate(Integer id, Model model) {model.addAttribute("blogTypeList", blogTypeService.getTypeList());Blog blog = blogService.findById(id);model.addAttribute("blog", blog);BlogType blogType = blog.getBlogType();if(blogType != null){model.addAttribute("typeId", blogType.getTypeId());}return "blog/update";}@RequestMapping("/add")public void add(Blog blog, @RequestParam(value = "img") MultipartFile file,Model model) throws Exception {// 获取原始文件名String fileName = file.getOriginalFilename();int index = fileName.indexOf(".");String imageUrl = null;String imagePath = DateUtils.getTimeStrForImage();if (index != -1) {//生成新文件名imageUrl = imagePath + fileName.substring(index);log.info("add {}", imagePath);handleFileUpload(file, imageUrl);blog.setImage(imageUrl);}// 添加博客及索引int result = blogService.add(blog);model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");}@RequestMapping("/update")public void update(Blog blog, @RequestParam(value = "img", required=false) MultipartFile file,Model model) throws Exception {if (file != null) {	 //上传图片// 获取原始文件名String fileName = file.getOriginalFilename();int index = fileName.indexOf(".");String imageUrl = null;String imagePath = DateUtils.getTimeStrForImage();if(index != -1){//生成新文件名imageUrl = imagePath + fileName.substring(index);log.info("update {}", imagePath);handleFileUpload(file,imageUrl);blog.setImage(imageUrl);}}//更新博客及索引int result = blogService.update(blog);model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");}@RequestMapping("/delete")public String delete(Integer id) throws IOException {// 删除博客、索引及评论blogService.delete(id);return "redirect:/blog/list.do";}@RequestMapping("/deletes")public String deletes(String ids) throws IOException {String[] idArr = org.springframework.util.StringUtils.commaDelimitedListToStringArray(ids);int len = idArr.length;Integer[] blogIds = new Integer[len];for (int i = 0; i < len; i++) {blogIds[i] = Integer.parseInt(idArr[i]);}blogService.batchDelete(blogIds);return "redirect:/blog/list.do";}private void handleFileUpload(MultipartFile file, String imageUrl) {try (InputStream is = file.getInputStream()) {// 获取输入流String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+Constants.COVER_DIR + imageUrl;File dir = new File(filePath.substring(0, filePath.lastIndexOf("/")));//判断上传目录是否存在if (!dir.exists()) {dir.mkdirs();}try (FileOutputStream fos = new FileOutputStream(new File(filePath))) {byte[] buffer = new byte[1024];int len = 0;// 读取输入流中的内容while ((len = is.read(buffer)) != -1) {fos.write(buffer, 0, len);}}} catch (Exception e) {log.error("图片上传失败", e);}}
}

BloggerAdminController 

package com.june.web.controller.admin;import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;import com.june.model.Blogger;
import com.june.service.BloggerService;
import com.june.service.CommentService;
import com.june.util.Constants;
import com.june.util.DateUtils;
import com.june.util.ResponseUtils;
import com.june.util.ShiroUtils;import lombok.extern.slf4j.Slf4j;@Controller
@RequestMapping("/blogger")
public @Slf4j class BloggerAdminController {@Resourceprivate CommentService commentService;@Resourceprivate BloggerService bloggerService;@RequestMapping("/toModifyInfo")public String toModifyInfo(Model model) {model.addAttribute("blogger", bloggerService.find());return "blogger/modifyInfo";}@RequestMapping("/toModifyPassword")public String toModifyPassword() {return "blogger/modifyPassword";}@RequestMapping("/modifyInfo")public void modifyInfo(Blogger blogger,@RequestParam(value = "img", required = false) MultipartFile file,Model model) throws Exception {if (file != null) {	 //上传图片// 获取原始文件名String fileName = file.getOriginalFilename();int index = fileName.indexOf(".");String imageUrl = null;if (index != -1) {// 生成新文件名imageUrl = DateUtils.getTimeStrForImage() + fileName.substring(index);handleFileUpload(file, imageUrl);blogger.setImageUrl(imageUrl);}}int result = bloggerService.update(blogger);model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");}@RequestMapping("/modifyPassword")public void modifyPassword(String newpwd, String oldpwd, String repwd, HttpServletResponse response,HttpServletRequest request) {Blogger blogger = bloggerService.find();if (!blogger.getPassword().equals(ShiroUtils.encryptPassword(oldpwd))) {ResponseUtils.writeText(response, "原密码输入不正确");return;}if (!newpwd.equals(repwd)) {ResponseUtils.writeText(response, "两次密码输入不一致");return;}blogger.setPassword(ShiroUtils.encryptPassword(newpwd));bloggerService.update(blogger);ResponseUtils.writeText(response, "修改成功");}private void handleFileUpload(MultipartFile file,String imageUrl) {try (InputStream is = file.getInputStream()) {// 获取输入流String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(0,Thread.currentThread().getContextClassLoader().getResource("").getPath().length()-16)+Constants.AVATAR_DIR + imageUrl;File dir = new File(filePath.substring(0, filePath.lastIndexOf("/")));//判断上传目录是否存在if (!dir.exists()) {dir.mkdirs();}try (FileOutputStream fos = new FileOutputStream(new File(filePath))) {byte[] buffer = new byte[1024];int len = 0;// 读取输入流中的内容while ((len = is.read(buffer)) != -1) {fos.write(buffer, 0, len);}}} catch (Exception e) {log.error("图片上传失败", e);}}
}

BlogTypeAdminController

package com.june.web.controller.admin;import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;import com.june.model.BlogType;
import com.june.model.PageBean;
import com.june.service.BlogService;
import com.june.service.BlogTypeService;
import com.june.util.Constants;
import com.june.util.PageUtils;
import com.june.util.ResponseUtils;/*** 博客类别Controller*/
@Controller
@RequestMapping("/blogType")
public class BlogTypeAdminController {@Resourceprivate BlogTypeService blogTypeService;@Resourceprivate BlogService blogService;@RequestMapping("/list")public String list(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = Constants.BACK_PAGE_SIZE + 3 + "") Integer pageSize,Model model, HttpServletRequest request) {int totalCount = blogTypeService.getCount();PageBean pageBean = new PageBean(totalCount, page, pageSize);Map params = new HashMap<>(2);params.put("start", pageBean.getStart());params.put("size", pageSize);List blogTypeList = blogTypeService.getTypeList(params);blogTypeList.forEach(blogType -> {Map types = new HashMap<>(1);types.put("typeId", blogType.getTypeId());Integer blogCount = blogService.getCount(types);blogType.setBlogCount(blogCount);});model.addAttribute("pagination", pageBean);String targetUrl = request.getContextPath() + "/blogType/list.do";String pageCode = PageUtils.genPagination(targetUrl, pageBean, "");model.addAttribute("pageCode", pageCode);model.addAttribute("entry", params);model.addAttribute("blogTypeList", blogTypeList);return "blogType/list";}@RequestMapping("/toAdd")public String toAdd() {return "blogType/add";}@RequestMapping("/toUpdate")public String toUpdate(Integer id,Model model) {model.addAttribute("blogType", blogTypeService.findById(id));return "blogType/update";}@RequestMapping("/add")public void add(BlogType blogType,Model model) {int result = blogTypeService.add(blogType);model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");}@RequestMapping("/update")public void update(BlogType blogType,Model model) {int result = blogTypeService.update(blogType);model.addAttribute("msg", result > 0 ? "保存成功" : "保存失败");}@RequestMapping("/search")public void search(Integer id,HttpServletResponse response){JSONObject jsonObj = new JSONObject();Map map = new HashMap<>(1);map.put("typeId", id);jsonObj.put("count", blogService.getCount(map));ResponseUtils.writeJson(response, jsonObj.toString());}//只删除类别@RequestMapping("/delete")public String delete(Integer id) {blogTypeService.delete(id);return "redirect:/blogType/list.do";}//删除的同时将相关博客的类别置为默认分类@RequestMapping("/batch_delete")public String batchDelete(Integer id) throws IOException {blogTypeService.batchDelete(id);return "redirect:/blogType/list.do";}
}

CommentAdminController

package com.june.web.controller.admin;import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;import com.june.model.Comment;
import com.june.model.PageBean;
import com.june.service.BlogService;
import com.june.service.CommentService;
import com.june.util.Constants;
import com.june.util.PageUtils;
import com.june.util.ResponseUtils;
import com.june.util.StringUtils;@Controller
@RequestMapping("/comment")
public class CommentAdminController {@Resourceprivate CommentService commentService;@Resourceprivate BlogService blogService;@RequestMapping("/list")public String list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = Constants.BACK_PAGE_SIZE + 1 + "") Integer pageSize,String firstDate, String secondDate, String userName, Boolean isPass, Model model, HttpServletRequest request) {Map params = new HashMap(6);params.put("firstDate", firstDate);params.put("secondDate", secondDate);params.put("userName", userName);params.put("isPass", isPass);int totalCount = commentService.getCount(params);PageBean pageBean = new PageBean(totalCount, page, pageSize);params.put("start", pageBean.getStart());params.put("size", pageSize);List commentList = commentService.getCommentList(params);commentList.stream().forEach(comment -> {String content = comment.getContent();if (content.length() > 60) {comment.setContent(content.substring(0,60) + "...");}});model.addAttribute("pagination", pageBean);StringBuilder param = new StringBuilder(); // 分页查询参数param.append(StringUtils.isEmpty(firstDate) ? "" : "&firstDate=" + firstDate);param.append(StringUtils.isEmpty(secondDate) ? "" : "&secondDate=" + secondDate);param.append(StringUtils.isEmpty(userName) ? "" : "&userName=" + userName);param.append(isPass == null ? "" : "&isPass=" + isPass);String pageCode = PageUtils.genPagination(request.getContextPath() + "/comment/list.do", pageBean, param.toString());model.addAttribute("pageCode", pageCode);model.addAttribute("entry", params);model.addAttribute("commentList", commentList);return "comment/list";}@RequestMapping("/toAdd")public String toAdd() {return "comment/add";}@RequestMapping("/detail")public String detail(Integer id,Model model){model.addAttribute("comment", commentService.findById(id));return "comment/detail";}//评论审核@RequestMapping("/audit")public void audit(Comment comment, HttpServletResponse response) {comment.setReplyDate(new Date());int result = commentService.audit(comment);JSONObject jsonObj = new JSONObject();jsonObj.put("success", result > 0);ResponseUtils.writeJson(response, jsonObj.toString());}@RequestMapping("/delete")public String delete(Integer id) throws IOException{commentService.delete(id);return "redirect:/comment/list.do";}@RequestMapping("/deletes")public String deletes(String ids) {String[] idArr = org.springframework.util.StringUtils.commaDelimitedListToStringArray(ids);int len = idArr.length;Integer[] commentIds = new Integer[len];for (int i = 0; i < len; i++) {commentIds[i] = Integer.parseInt(idArr[i]);}commentService.batchDelete(commentIds);return "redirect:/comment/list.do";}
}

如果也想学习本系统,下面领取。关注并回复:103ssm 

 

相关内容

热门资讯

埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
脚上的穴位图 脚面经络图对应的... 人体穴位作用图解大全更清晰直观的标注了各个人体穴位的作用,包括头部穴位图、胸部穴位图、背部穴位图、胳...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
demo什么意思 demo版本... 618快到了,各位的小金库大概也在准备开闸放水了吧。没有小金库的,也该向老婆撒娇卖萌服个软了,一切只...
埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...