基于javaweb+mysql的ssm个人博客管理系统(java+ssm+html+jq+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM个人博客管理系统(java+ssm+html+jq+jsp+mysql)
项目介绍
管理员角色包含以下功能: 发博客,审核评论,博客增删改查,博客类别增删改查,修改导航,评论增删改查,个人信息修改,登陆页面等功能。
游客角色包含以下功能: 博客首页,查看博客详情,按照日志类别查找,发表评论等功能。
环境需要
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版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/blogs/save")
@ResponseBody
public Result save(@RequestParam("blogTitle") String blogTitle,
@RequestParam(name = "blogSummary", required = false) String blogSummary,
@RequestParam("blogCategoryId") Integer blogCategoryId,
@RequestParam("blogTags") String blogTags,
@RequestParam("blogContent") String blogContent,
@RequestParam("blogStatus") Byte blogStatus,
* @param loginUserName 登录名
* @param nickName 昵称
* @return java.lang.String
*/
@PostMapping("/profile/name")
@ResponseBody
public String nameUpdate(HttpServletRequest request, @RequestParam("loginUserName") String loginUserName,
@RequestParam("nickName") String nickName) {
if (StringUtils.isEmpty(loginUserName) || StringUtils.isEmpty(nickName)) {
return "参数不能为空";
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
if (adminUserService.updateName(loginUserId, loginUserName, nickName)) {
return "success";
return ResultGenerator.genFailResult("参数异常!");
PageQueryUtil pageUtil = new PageQueryUtil(params);
return ResultGenerator.genSuccessResult(blogService.getBlogsPage(pageUtil));
/**
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/blogs")
public String list(HttpServletRequest request) {
request.setAttribute("path", "blogs");
return "admin/blog";
/**
* @param ids
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(@RequestBody Integer[] ids) {
if (ids.length < 1) {
return ResultGenerator.genFailResult("参数异常!");
if (categoryService.deleteBatch(ids)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("删除失败");
博客管理控制层:
* @param blogId 博客id
* @return java.lang.String
*/
@GetMapping("/blogs/edit/{blogId}")
public String edit(HttpServletRequest request, @PathVariable("blogId") Long blogId) {
request.setAttribute("path", "edit");
Blog blog = blogService.getBlogById(blogId);
if (blog == null) {
return "error/error_400";
request.setAttribute("blog", blog);
request.setAttribute("categories", categoryService.getAllCategories());
private BlogService blogService;
@Resource
private CategoryService categoryService;
/**
* 博客列表
* @param params 参数
* @return com.hbu.myblog.util.Result
*/
@GetMapping("/blogs/list")
@ResponseBody
public Result list(@RequestParam Map<String, Object> params) {
if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
return ResultGenerator.genFailResult("参数异常!");
session.setAttribute("errorMsg", "登陆失败");
return "admin/login";
/**
* 修改个人信息
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/profile")
public String profile(HttpServletRequest request) {
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
AdminUser adminUser = adminUserService.getUserDetailById(loginUserId);
if (adminUser == null) {
return "admin/login";
Blog blog = blogService.getBlogById(blogId);
if (blog == null) {
return "error/error_400";
request.setAttribute("blog", blog);
request.setAttribute("categories", categoryService.getAllCategories());
return "admin/edit";
/**
* 添加文章
* @param blogTitle 文章标题
* @param blogSummary 摘要
* @param blogCategoryId 类别
* @return com.hbu.myblog.util.Result
*/
@PostMapping("/blogs/save")
@ResponseBody
public Result save(@RequestParam("blogTitle") String blogTitle,
@RequestParam(name = "blogSummary", required = false) String blogSummary,
@RequestParam("blogCategoryId") Integer blogCategoryId,
@RequestParam("blogTags") String blogTags,
@RequestParam("blogContent") String blogContent,
@RequestParam("blogStatus") Byte blogStatus,
@RequestParam("enableComment") Byte enableComment) {
if (StringUtils.isEmpty(blogTitle)) {
if (StringUtils.isEmpty(categoryName)) {
return ResultGenerator.genFailResult("请输入分类名称!");
if (StringUtils.isEmpty(categoryIcon)) {
return ResultGenerator.genFailResult("请选择分类图标!");
if (categoryService.updateCategory(categoryId, categoryName, categoryIcon)) {
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("分类名称重复");
/**
* @param ids
* @return com.hbu.myblog.util.Result
*/
@RequestMapping(value = "/categories/delete", method = RequestMethod.POST)
/**
* 修改文章
* @param blogId 文章ID
* @param blogTitle 文章标题
* @param blogSummary 摘要
* @param blogCategoryId 类别
* @param blogTags 标签
* @param blogContent 内容
* @param blogStatus 草稿,发布
* @param enableComment 可否评论
* @return com.hbu.myblog.util.Result
* @param userName 用户名
* @param password 密码
* @param verifyCode 验证码
* @param session session
* @return java.lang.String
*/
@PostMapping(value = "/login")
public String login(@RequestParam("userName") String userName,
@RequestParam("password") String password,
@RequestParam("verifyCode") String verifyCode,
HttpSession session) {
if (StringUtils.isEmpty(verifyCode)) {
session.setAttribute("errorMsg", "验证码不能为空");
session.setAttribute("errorMsg", "验证码错误");
return "admin/login";
AdminUser adminUser = adminUserService.login(userName, password);
if (adminUser != null) {
session.setAttribute("loginUser", adminUser.getNickName());
session.setAttribute("loginUserId", adminUser.getAdminUserId());
//session过期时间设置为7200秒 即两小时
//session.setMaxInactiveInterval(60 * 60 * 2);
return "redirect:/admin/index";
} else {
session.setAttribute("errorMsg", "登陆失败");
return "admin/login";
/**
* 修改个人信息
request.setAttribute("commentCount", commentService.getTotalComments());
return "admin/index";
/**
* 登录界面
* @param userName 用户名
* @param password 密码
* @param verifyCode 验证码
* @param session session
* @return java.lang.String
*/
@PostMapping(value = "/login")
public String login(@RequestParam("userName") String userName,
@RequestParam("password") String password,
request.setAttribute("path", "blogs");
return "admin/blog";
/**
* @param request http请求
* @return java.lang.String
*/
@GetMapping("/blogs/edit")
public String edit(HttpServletRequest request) {
request.setAttribute("path", "edit");
request.setAttribute("categories", categoryService.getAllCategories());
return "admin/edit";
/**
* @param request http请求
@PostMapping("/profile/name")
@ResponseBody
public String nameUpdate(HttpServletRequest request, @RequestParam("loginUserName") String loginUserName,
@RequestParam("nickName") String nickName) {
if (StringUtils.isEmpty(loginUserName) || StringUtils.isEmpty(nickName)) {
return "参数不能为空";
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
if (adminUserService.updateName(loginUserId, loginUserName, nickName)) {
return "success";
} else {
return "修改失败";
/**
* 管理员退出
public String edit(HttpServletRequest request, @PathVariable("blogId") Long blogId) {
request.setAttribute("path", "edit");
Blog blog = blogService.getBlogById(blogId);
if (blog == null) {
return "error/error_400";
request.setAttribute("blog", blog);
request.setAttribute("categories", categoryService.getAllCategories());
return "admin/edit";
/**
* 添加文章
* @param blogTitle 文章标题