Java项目:SSM个人博客管理系统

news2024/10/7 15:23:44

作者主页:源码空间站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版本;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:HTML+CSS+JavaScript+jsp

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

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

运行截图

相关代码

博客Controller

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 {

	@Resource
	private BlogService blogService;

	@Resource
	private BlogTypeService blogTypeService;

	@Resource
	private CommentService commentService;
	
	@Resource
	private 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<String, Object> 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<BlogType> 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);
		}
	}
}

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/80581.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

TOOD: Task-aligned One-stage Object Detection 原理与代码解析

paper&#xff1a;TOOD: Task-aligned One-stage Object Detection code&#xff1a;https://github.com/fcjian/TOOD 存在的问题 目标检测包括分类和定位两个子任务&#xff0c;分类任务学习的特征主要关注物体的关键或显著区域&#xff0c;而定位任务是为了精确定位整个…

SpringBoot yaml语法详解

SpringBoot yaml语法详解1.yaml基本语法2.yaml给属性赋值3.JSR303校验4.SpringBoot的多环境配置1.yaml基本语法 通常情况下&#xff0c;Spring Boot 在启动时会将 resources 目录下的 application.properties 或 apllication.yaml 作为其默认配置文件&#xff0c;我们可以在该…

【云原生 | Kubernetes 实战】11、K8s 控制器 Deployment 入门到企业实战应用(下)

目录 四、通过 k8s 实现滚动更新 4.3 自定义滚动更新策略 取值范围 建议配置 总结 测试&#xff1a;自定义策略 重建式更新&#xff1a;Recreate 五、生产环境如何实现蓝绿部署&#xff1f; 5.1 什么是蓝绿部署&#xff1f; 5.2 蓝绿部署的优势和缺点 优点&#x…

图数据库 Neo4j 学习之JAVA-API操作

Neo4j 系列 1、图数据库 Neo4j 学习随笔之基础认识 2、图数据库 Neo4j 学习随笔之核心内容 3、图数据库 Neo4j 学习随笔之基础操作 4、图数据库 Neo4j 学习随笔之高级操作 5、图数据库 Neo4j 学习之JAVA-API操作 6、图数据库 Neo4j 学习之SpringBoot整合 文章目录Neo4j 系列前…

mac pro M1(ARM)安装vmware虚拟机及centos8详细教程

前言 mac发布了m1芯片&#xff0c;其强悍的性能收到很多开发者的追捧&#xff0c;但是也因为其架构的更换&#xff0c;导致很多软件或环境的安装成了问题&#xff0c;这次我们接着来看如何在mac m1环境下安装centos8 Centos8安装安装vmware虚拟机Centos8 镜像支持M1芯片安装Cen…

DDPM原理与代码剖析

前言 鸽了好久没更了&#xff0c;主要是刚入学学业压力还蛮大&#xff0c;挺忙的&#xff0c;没时间总结啥东西。 接下来就要好好搞科研啦。先来学习一篇diffusion的经典之作Denoising Diffusion Probabilistic Models(DDPM)。 先不断前向加高斯噪声&#xff0c;这一步骤称为…

论文笔记(二十三):Predictive Sampling: Real-time Behaviour Synthesis with MuJoCo

Predictive Sampling: Real-time Behaviour Synthesis with MuJoCo文章概括摘要1. 介绍2. 背景3. MuJoCo MPC (MJPC)3.1. 物理模拟3.2. 目标3.3. 样条3.4. 规划师4. 结论4.1. 图形用户界面4.2. 例子5. 讨论5.1. 预测抽样5.2. 用例5.3. 局限和未来的工作文章概括 作者&#xff…

25-Vue之ECharts-基本使用

ECharts-基本使用前言ECharts介绍ECharts快速上手ECharts配置说明前言 本篇开始来学习下开源可视化库ECharts ECharts介绍 ECharts是百度公司开源的一个使用 JavaScript 实现的开源可视化库&#xff0c;兼容性强&#xff0c;底层依赖矢量图形 库 ZRender &#xff0c;提供直…

Oracle High Water Mark问题

公司写SQL时遇到一个奇怪的问题&#xff0c;往表中频繁插入和删除大量数据&#xff0c;几次操作后&#xff0c;使用Select查询(表中没数据)特别慢&#xff0c;后得知是高水位线的问题。 该问题已通过: truncate table tableName语句解决。 本想写篇文章详细记录一下的&#xff…

操作系统,计算机网络,数据库刷题笔记9

操作系统&#xff0c;计算机网络&#xff0c;数据库刷题笔记9 2022找工作是学历、能力和运气的超强结合体&#xff0c;遇到寒冬&#xff0c;大厂不招人&#xff0c;可能很多算法学生都得去找开发&#xff0c;测开 测开的话&#xff0c;你就得学数据库&#xff0c;sql&#xff…

聊聊远程项目交付的敏捷管理

这是鼎叔的第四十三篇原创文章。行业大牛和刚毕业的小白&#xff0c;都可以进来聊聊。 欢迎关注本人专栏和微信公众号《敏捷测试转型》&#xff0c;大量原创思考文章陆续推出。 对于日益重要的国际化市场&#xff0c;越来越多的离岸项目&#xff08;内包或外包&#xff09;在…

这十套练习,教你如何用Pandas做数据分析(09)

练习9-时间序列 探索Apple公司股价数据 步骤1 导入必要的库 运行以下代码 import pandas as pd import numpy as np visualization import matplotlib.pyplot as plt %matplotlib inline 步骤2 数据集地址 运行以下代码 path9 ‘…/input/pandas_exercise/pandas_exer…

CVE-2019-11043(PHP远程代码执行漏洞)复现

今天继续给大家介绍渗透测试相关知识&#xff0c;本文主要内容是CVE-2019-11043&#xff08;PHP远程代码执行漏洞&#xff09;复现。 免责声明&#xff1a; 本文所介绍的内容仅做学习交流使用&#xff0c;严禁利用文中技术进行非法行为&#xff0c;否则造成一切严重后果自负&am…

【hexo系列】02.hexo和obsidian实现笔记丝滑

文章目录hexo主题hexo进阶hexo插件&#xff1a;自动生成目录hexo插件&#xff1a;自动生成目录序号&#xff08;自行选用&#xff09;obsidian插件&#xff1a;templater安装插件配置插件定制模板新建笔记参考资料hexo主题 hexo主题大全 cd blog git clone https://github.co…

这十套练习,教你如何用Pandas做数据分析(08)

练习8-创建数据框 探索Pokemon数据 步骤1 导入必要的库 运行以下代码 import pandas as pd 步骤2 创建一个数据字典 运行以下代码 raw_data {“name”: [‘Bulbasaur’, ‘Charmander’,‘Squirtle’,‘Caterpie’], “evolution”: [‘Ivysaur’,‘Charmeleon’,‘Warto…

链接的接口——符号

链接的接口——符号 链接过程的本质就是要把多个不同的目标文件之间相互“粘”到一起&#xff0c;或者说像玩具积木一样&#xff0c;可以拼装形成一个整体。为了使不同目标文件之间能够相互粘合&#xff0c;这些目标文件之间必须有固定的规则才行&#xff0c;就像积木模块必须…

Akka 学习(八)路由与Dispatcher

目录一 编发编程二 Actor路由2.1 路由的作用2.2 路由的创建方式2.3 路由策略2.4 广播消息2.5 监督路由对象2.6 Akka 案例三 Dispatcher 任务分发3.1 什么是Dispatcher&#xff1f;3.2 Dispatcher的线程池3.3 Dispatcher的分类一 编发编程 Akka 是一个用于实现分布式、并发、响…

mPEG-Phosphate,甲氧基-聚乙二醇-磷酸盐试剂供应

一&#xff1a;产品描述 1、名称 英文&#xff1a;mPEG-Phosphate 中文&#xff1a;甲氧基-聚乙二醇-磷酸盐 2、CAS编号&#xff1a;N/A 3、所属分类&#xff1a;Phosphate PEG Methoxy PE 4、分子量&#xff1a;可定制&#xff0c;2000/1000/3400/20000/5000/10000 5、…

认识Java中的反射与枚举

作者&#xff1a;~小明学编程 文章专栏&#xff1a;JavaSE基础 格言&#xff1a;目之所及皆为回忆&#xff0c;心之所想皆为过往 目录 反射 什么是反射&#xff1f; 常用的反射类 Class类 Class类中的相关方法 常用获得类中属性相关的方法 获得类中注解相关的方法 获得…

Java中的运算符--短路运算

文章目录0 写在前面1 介绍2 举例2.1 逻辑与 &&2.2 逻辑或 ||3 小技巧4 写在最后0 写在前面 JAVA中有两个短路运算&#xff0c;一个是短路与&#xff0c;一个是短路或。 所谓短路&#xff0c;就是当一个参与运算的操作数足以推断该表达式的值时&#xff0c;另一个操作数…