资讯 小学 初中 高中 语言 会计职称 学历提升 法考 计算机考试 医护考试 建工考试 教育百科
栏目分类:
子分类:
返回
空麓网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
空麓网 > 计算机考试 > 软件开发 > 后端开发 > Java

springboot+mybatis+mysql实现的个人博客管理系统(功能包含登录,栏目管理、文章管理、评论管理、系统设置、用户管理、发布博客、评论等)

Java 更新时间: 发布时间: 计算机考试归档 最新发布

springboot+mybatis+mysql实现的个人博客管理系统(功能包含登录,栏目管理、文章管理、评论管理、系统设置、用户管理、发布博客、评论等)

博客目录

  • springboot+mybatis实现的个人博客管理系统
    • 实现功能截图
    • 系统功能
    • 使用技术
    • 代码
    • 完整源码

springboot+mybatis实现的个人博客管理系统

本系统是一个个人博客管理系统,比较新的框架springboot+mybatis实现,分为普通用户和管理员,普通用户可以发布博客、发表评论、查看博客,管理员可以对栏目、文章、评论、用户等进行管理。
(文末查看完整源码)

实现功能截图

前台首页

博客详情’

留言

栏目管理

博客文章管理

博客评论管理

系统设置

用户管理

系统功能

本系统实现了以下功能:
1、登录
2、文章管理、新增文章
3、栏目管理
4、评论管理
5、系统设置
6、用户管理
7、留言管理
8、博客详情
9、博客评论

使用技术

数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:springboot+mybatis

项目结构

代码

java端
实体类
Admin.java

package com.lee.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;


public class Admin extends Model {

    private static final long serialVersionUID = 1L;

    
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    
    @NotEmpty(message = "用户名不能为空!")
    private String username;

    
    @NotEmpty(message = "密码不能为空!")
    private String password;

    
    @NotEmpty(message = "昵称不能为空!")
    private String nickname;

    
    @NotEmpty(message = "邮箱不能为空!")
    @Email(message = "邮箱格式不正确")
    private String email;

    
    private Integer status;

    
    private Integer isSupper;

    
    private String createTime;

    
    private String updateTime;

    
    private String deleteTime;

    @TableLogic
    private Integer isdel;//逻辑删除字段 0 未删除 1已删除

    public Integer getIsdel() {
        return isdel;
    }

    public void setIsdel(Integer isdel) {
        this.isdel = isdel;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
    public Integer getIsSupper() {
        return isSupper;
    }

    public void setIsSupper(Integer isSupper) {
        this.isSupper = isSupper;
    }
    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
    public String getDeleteTime() {
        return deleteTime;
    }

    public void setDeleteTime(String deleteTime) {
        this.deleteTime = deleteTime;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "SbAdmin{" +
        "id=" + id +
        ", username=" + username +
        ", password=" + password +
        ", nickname=" + nickname +
        ", email=" + email +
        ", status=" + status +
        ", isSupper=" + isSupper +
        ", createTime=" + createTime +
        ", updateTime=" + updateTime +
        ", deleteTime=" + deleteTime +
        "}";
    }
}

Article.java

package com.lee.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;


public class Article extends Model
{ private static final long serialVersionUID = 1L; @TableId(value = "id", type = IdType.AUTO) private Integer id; @NotEmpty(message = "文章标题不能为空") private String title; private String artdesc; @NotEmpty(message = "文章标签不能为空") private String tags; private String content; private Integer isTop; private Integer cateId; private String createTime; private String updateTime; private String deleteTime; @TableLogic private Integer isdel; private Integer memberId; @NotEmpty(message = "文章作者不能为空") private String authorname; private Integer viewnum; private Integer commentnum; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public String getArtdesc() { return artdesc; } public void setArtdesc(String artdesc) { this.artdesc = artdesc; } public void setTitle(String title) { this.title = title; } public String getTags() { return tags; } public void setTags(String tags) { this.tags = tags; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public Integer getIsTop() { return isTop; } public void setIsTop(Integer isTop) { this.isTop = isTop; } public Integer getCateId() { return cateId; } public void setCateId(Integer cateId) { this.cateId = cateId; } public String getCreateTime() { return createTime; } public void setCreateTime(String createTime) { this.createTime = createTime; } public String getUpdateTime() { return updateTime; } public void setUpdateTime(String updateTime) { this.updateTime = updateTime; } public String getDeleteTime() { return deleteTime; } public void setDeleteTime(String deleteTime) { this.deleteTime = deleteTime; } public Integer getIsdel() { return isdel; } public void setIsdel(Integer isdel) { this.isdel = isdel; } public Integer getMemberId() { return memberId; } public void setMemberId(Integer memberId) { this.memberId = memberId; } public Integer getViewnum() { return viewnum; } public void setViewnum(Integer viewnum) { this.viewnum = viewnum; } public Integer getCommentnum() { return commentnum; } public void setCommentnum(Integer commentnum) { this.commentnum = commentnum; } public String getAuthorname() { return authorname; } public void setAuthorname(String authorname) { this.authorname = authorname; } @Override protected Serializable pkVal() { return this.id; } @Override public String toString() { return "Article{" + "id=" + id + ", title=" + title + ", desc=" + artdesc + ", tags=" + tags + ", authorname" + authorname + ", content=" + content + ", isTop=" + isTop + ", cateId=" + cateId + ", createTime=" + createTime + ", updateTime=" + updateTime + ", deleteTime=" + deleteTime + ", isdel=" + isdel + ", memberId=" + memberId + ", viewnum=" + viewnum + ", commentnum=" + commentnum + "}"; } }

service层
AdminServiceImpl.java

package com.lee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lee.entity.Admin;
import com.lee.mapper.AdminMapper;
import com.lee.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service
public class AdminServiceImpl extends ServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    
    public Admin getInfoByUsernameAndPassword(String username, String password){
       Admin admin =  adminMapper.selectOne(new QueryWrapper().eq("username",username).eq("password",password));
        return admin;
    }

    
    public  IPage> getPageInfo(Map queryParam,int offset,int size){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(queryParam.get("username") != null) {
            queryWrapper.like("username",queryParam.get("username"));
        }
        if(queryParam.get("nickname") != null) {
            queryWrapper.like("nickname",queryParam.get("nickname"));
        }

        if(queryParam.get("email") != null) {
            queryWrapper.like("email",queryParam.get("email"));
        }
        queryWrapper.orderByDesc("create_time");
        Page page = new Page(offset/size +1,size);
        IPage> mapIPage = adminMapper.selectMapsPage(page, queryWrapper);
        return mapIPage;
    }

    
    public Admin getByUsername(String username){
       return  adminMapper.selectOne(new QueryWrapper().eq("username",username));
    }

    

}

ArticleServiceImpl.java

package com.lee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.lee.entity.Article;
import com.lee.entity.Comment;
import com.lee.mapper.ArticleMapper;
import com.lee.mapper.CommentMapper;
import com.lee.service.ArticleService;
import com.lee.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class ArticleServiceImpl extends ServiceImpl implements ArticleService {
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    CommentMapper commentMapper;

    public IPage> getPageInfo(Map queryParam,int offset,int size){
        QueryWrapper
queryWrapper = new QueryWrapper<>(); if(queryParam.get("title") != null) { queryWrapper.like("title",queryParam.get("title")); } queryWrapper.orderByDesc("create_time"); Page
page = new Page
(offset/size+1,size); IPage> mapIPage = articleMapper.selectMapsPage(page,queryWrapper); return mapIPage; } public IPage> getPageInfoByPageNum(Map queryParam,int pagenum,int size){ QueryWrapper
queryWrapper = new QueryWrapper<>(); if(queryParam.get("title") != null) { queryWrapper.like("title",queryParam.get("title")); } if(queryParam.get("cateid") != null) { queryWrapper.eq("cate_id",queryParam.get("cateid")); } queryWrapper.orderByDesc("create_time"); Page
page = new Page
(pagenum,size); IPage> mapIPage = articleMapper.selectMapsPage(page,queryWrapper); return mapIPage; } public boolean deleteArticleAndCommentById(Integer id){ commentMapper.deleteByArticleId(id); return SqlHelper.delBool(articleMapper.deleteById(id)); } public Article getNextInfo(Map searchParam){ return this.articleMapper.getNextInfo(searchParam); } public Article getPreInfo(Map searchParam){ return this.articleMapper.getPreInfo(searchParam); } }

controller层
ArticleController.java

package com.lee.controller.admin;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lee.common.DataGrid;
import com.lee.common.DateTimeUtil;
import com.lee.common.Message;
import com.lee.entity.Admin;
import com.lee.entity.Article;
import com.lee.service.ArticleService;
import com.lee.service.CateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/admin/article")
public class ArticleController extends BasicController {
    @Autowired
    ArticleService articleService;
    @Autowired
    CateService cateService;
    @GetMapping("list")
    public String list(){
        return "admin/article/list";
    }
    @PostMapping("findList")
    @ResponseBody
    public DataGrid findList(@RequestBody JSONObject jsonObject){
        Map searchParams = (HashMap) jsonObject.get("search");
        int offset = "".equals(jsonObject.getString("offset")) ? 0 : jsonObject.getIntValue("offset");
        int size = "".equals(jsonObject.getString("limit")) ? 10 : jsonObject.getIntValue("limit");

        IPage> page = articleService.getPageInfo(searchParams, offset, size);

        DataGrid result = new DataGrid();
        result.setTotal(page.getTotal());
        result.setRows(page.getRecords());
        return result;
    }
    @GetMapping("add")
    public String add(Model model) {
        model.addAttribute("cateInfos",cateService.getList());
        return "admin/article/add";
    }

    @PostMapping("add")
    @ResponseBody
    public Message doAdd(@Validated Article article, HttpServletRequest request){
        try {
            Admin admin = getCurrentUser(request);
            if(admin != null) {
                if(article.getIsTop() == null) {
                    article.setIsTop(0);
                }
                article.setCreateTime(DateTimeUtil.nowTimeStr());
                article.setMemberId(admin.getId());
                articleService.save(article);
                return Message.success("文章添加成功!");
            } else {
                return Message.fail("登录超时,请重新登录!",null,"/admin/login");
            }
        } catch (Exception e) {
            return Message.fail("文章数据保存异常,保存失败!");
        }

    }
    @PostMapping("top")
    @ResponseBody
    public Message top(@RequestParam(value = "id")Integer id,@RequestParam(value = "istop")Integer istop){
        try{
           Article article =  articleService.getById(id);
           if(article != null) {
               if(istop == 1) {
                   article.setIsTop(0);
               } else if(istop == 0) {
                   article.setIsTop(1);
               }
               articleService.updateById(article);
               return Message.success("操作成功!");
           } else {
               return Message.fail("文章不存在或已被删除,操作失败!");
           }
        } catch (Exception e) {
            return Message.fail("文章推荐操作处理异常!");
        }
    }
    @GetMapping("/update/{id}")
    public String update(@PathVariable Integer id,Model model){
       Article article =  articleService.getById(id);
        model.addAttribute("cateInfos",cateService.getList());
        model.addAttribute("articleInfo",article);
       return "admin/article/update";
    }
    @PostMapping("/update")
    @ResponseBody
    public Message doUpdate(@Validated Article article){
        try{
            Article articleInfo = articleService.getById(article.getId());
            if(articleInfo != null) {
                if(article.getIsTop() == null) {
                    articleInfo.setIsTop(0);
                } else {
                    articleInfo.setIsTop(article.getIsTop());
                }

                articleInfo.setTitle(article.getTitle());
                articleInfo.setAuthorname(article.getAuthorname());
                articleInfo.setTags(article.getTags());
                articleInfo.setArtdesc(article.getArtdesc());
                articleInfo.setContent(article.getContent());
                articleInfo.setCateId(article.getCateId());
                articleInfo.setUpdateTime(DateTimeUtil.nowTimeStr());
                articleService.updateById(articleInfo);
                return Message.success("文章修改成功!");
            } else {
                return Message.fail("文章不存在或已被删除!");
            }
        } catch (Exception e) {
            return Message.fail("文章修改保存异常,操作失败!");
        }
    }
    @PostMapping("delete")
    @ResponseBody
    public Message delete(@RequestParam(value = "ids") List ids) {
        try {
            for (int id : ids) {
                articleService.deleteArticleAndCommentById(id);
            }
            return Message.success("文章删除成功");
        } catch (Exception e) {
            return Message.fail("文章删除异常!");
        }
    }

}

UserController.java

package com.lee.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lee.common.DataGrid;
import com.lee.common.DateTimeUtil;
import com.lee.common.Message;
import com.lee.entity.Admin;
import com.lee.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin/user")
public class UserController extends BasicController {
    @Autowired
    AdminService adminService;
    
    @RequestMapping("list")
    public String list(HttpServletRequest request){
        //TODO 超级管理员权限控制
        if(getCurrentUser(request).getIsSupper() == 1) {
            return "admin/user/list";
        } else {
            return "admin/home";
        }

    }

    
    @RequestMapping("findList")
    @ResponseBody
    public  DataGrid findList(@RequestBody JSONObject jsonObject){
        //获取查询参数
        Map searchParams = (HashMap)jsonObject.get("search");
        int offset = "".equals(jsonObject.getString("offset"))?0:jsonObject.getIntValue("offset");
        int size = "".equals(jsonObject.getString("limit"))?10:jsonObject.getIntValue("limit");

        IPage> page = adminService.getPageInfo(searchParams,offset,size);
        DataGrid result = new DataGrid();
        result.setRows(page.getRecords());
        result.setTotal(page.getTotal());
        return result;
    }

    
    @GetMapping("add")
    public String add(){

        return "admin/user/add";
    }
    @PostMapping("add")
    @ResponseBody
    public Message doAdd(@Validated Admin admin,@RequestParam(value = "confirmpassword") String confirmpassword){
        try{
            //TOTO 可以在service里添加条件验证规则
            if(adminService.getByUsername(admin.getUsername()) != null) {
                return Message.fail("该用户已存在!");
            }
            if(!confirmpassword.equals(admin.getPassword())) {
                return Message.fail("密码和确认密码不一致!");
            }
            admin.setCreateTime(DateTimeUtil.nowTimeStr());
            adminService.save(admin);
            return Message.success("管理员创建成功!");
        } catch (Exception e) {
            return Message.fail("创建保存异常!");
        }
    }


    
    @PostMapping("check")
    @ResponseBody
    public boolean check(@RequestParam String username){
        if(StringUtils.isEmpty(username)){
            return false;
        }
        Admin admin = adminService.getByUsername(username);
        if(admin != null) {
            return false;
        }
        return true;
    }

    @PostMapping("status")
    @ResponseBody
    public Message status(@RequestParam Integer id){
        try {
            Admin admin = adminService.getById(id);
            if (admin != null) {
                String message = admin.getStatus() == 0 ? "管理员禁用成功!" : "管理员启用成功!";
                admin.setStatus(admin.getStatus() == 0 ? 1 : 0);
                adminService.updateById(admin);
                return Message.success(message);
            } else {
                return Message.fail("管理员信息不存在或已被删除!");
            }
        }catch ( Exception e) {
            return Message.fail("数据操作异常");
        }
    }

    
    @GetMapping("update/{id}")
    public String update(@PathVariable Integer id, Model model){
        Admin admin = adminService.getById(id);
        if(admin != null) {
            model.addAttribute("adminInfo",admin);
        } else {
            //TODO 对象已删除,跳转到错误页面
        }
        return "admin/user/update";
    }

    
    @PostMapping("update")
    @ResponseBody
    public Message doUpdate(@Validated Admin admin, HttpServletRequest request){
        try {
            String oldpassword = request.getParameter("oldpassword");
            String newpassword = request.getParameter("newpassword");
           Admin adminInfo = adminService.getById(admin.getId());
           if(StringUtils.isEmpty(newpassword)) {//TODO 增加密码规则验证
               return Message.fail("新密码不能为空");
           }
           if(adminInfo != null) {
               if(oldpassword.equals(adminInfo.getPassword())) {
                   adminInfo.setPassword(newpassword);
                   adminInfo.setNickname(admin.getNickname());
                   adminInfo.setEmail(admin.getEmail());
                   adminInfo.setIsSupper(admin.getIsSupper());
                   adminInfo.setUpdateTime(DateTimeUtil.nowTimeStr());
                   adminService.updateById(adminInfo);
                   return Message.success("管理员信息修改成功");
               } else {
                   return Message.fail("原密码输入错误");
               }
           } else {
               return Message.fail("管理员不存在或已被删除");
           }
        } catch (Exception e) {
            return Message.fail("修改失败");
        }

    }

    @GetMapping("view/{id}")
    public String view(@PathVariable Integer id,Model model){
        Admin adminInfo = adminService.getById(id);
        if(adminInfo != null) {
            model.addAttribute("adminInfo",adminInfo);
        } else{
            //TODO 跳转错误页面
        }
        return "admin/user/view";
    }
    @PostMapping("delete")
    @ResponseBody
    public Message delete(@RequestParam(value = "ids") List ids){
        try {
            for (int id :ids) {
                adminService.removeById(id);
            }
            return Message.success("删除成功");
        } catch (Exception e){
           return Message.fail("删除异常!");
        }
    }
}

完整源码

觉得有用,记得一键三连哦!

转载请注明:文章转载自 http://www.konglu.com/
本文地址:http://www.konglu.com/it/1093534.html
免责声明:

我们致力于保护作者版权,注重分享,被刊用文章【springboot+mybatis+mysql实现的个人博客管理系统(功能包含登录,栏目管理、文章管理、评论管理、系统设置、用户管理、发布博客、评论等)】因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理,本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即通知我们,情况属实,我们会第一时间予以删除,并同时向您表示歉意,谢谢!

我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2023 成都空麓科技有限公司

ICP备案号:蜀ICP备2023000828号-2