• (免费分享)基于springboot博客系统


    源码获取:关注文末gongzhonghao,输入015领取下载链接

    开发工具:IDEA,数据库mysql

    技术:springboot+mybatis-plus+redis

    系统分用户前台和管理后台

    前台截图:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    后台截图:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    package com.puboot.module.admin.controller;
    
    import cn.hutool.core.collection.CollUtil;
    import com.puboot.common.util.CoreConst;
    import com.puboot.common.util.ResultUtil;
    import com.puboot.module.admin.model.BizArticle;
    import com.puboot.module.admin.model.BizCategory;
    import com.puboot.module.admin.service.BizArticleService;
    import com.puboot.module.admin.service.BizCategoryService;
    import com.puboot.module.admin.vo.base.ResponseVo;
    import lombok.AllArgsConstructor;
    import org.springframework.cache.annotation.CacheEvict;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.*;
    import org.thymeleaf.util.ListUtils;
    
    import java.util.Date;
    import java.util.List;
    
    /**
     * 后台类目管理
     */
    @Controller
    @RequestMapping("category")
    @AllArgsConstructor
    public class CategoryController {
    
        private final BizCategoryService categoryService;
        private final BizArticleService articleService;
    
        @PostMapping("list")
        @ResponseBody
        public List<BizCategory> loadCategory(boolean isFistLevel) {
            BizCategory bizCategory = new BizCategory();
            bizCategory.setStatus(CoreConst.STATUS_VALID);
            if (isFistLevel) {
                bizCategory.setPid(CoreConst.TOP_MENU_ID);
            }
            return categoryService.selectCategories(bizCategory);
        }
    
        @GetMapping("/add")
        public String add() {
            return CoreConst.ADMIN_PREFIX + "category/form";
        }
    
        @PostMapping("/add")
        @ResponseBody
        @CacheEvict(value = "category", allEntries = true)
        public ResponseVo add(BizCategory bizCategory) {
            if (!CoreConst.TOP_MENU_ID.equals(bizCategory.getPid())) {
                List<BizArticle> bizArticles = articleService.selectByCategoryId(bizCategory.getPid());
                if (!ListUtils.isEmpty(bizArticles)) {
                    return ResultUtil.error("添加失败,父级分类下存在文章");
                }
            }
            Date date = new Date();
            bizCategory.setCreateTime(date);
            bizCategory.setUpdateTime(date);
            bizCategory.setStatus(CoreConst.STATUS_VALID);
            boolean i = categoryService.save(bizCategory);
            if (i) {
                return ResultUtil.success("新增分类成功");
            } else {
                return ResultUtil.error("新增分类失败");
            }
        }
    
        @GetMapping("/edit")
        public String edit(Model model, Integer id) {
            BizCategory bizCategory = categoryService.selectById(id);
            model.addAttribute("category", bizCategory);
            return CoreConst.ADMIN_PREFIX + "category/form";
        }
    
        @PostMapping("/edit")
        @ResponseBody
        @CacheEvict(value = "category", allEntries = true)
        public ResponseVo edit(BizCategory bizCategory) {
            bizCategory.setUpdateTime(new Date());
            boolean i = categoryService.updateById(bizCategory);
            if (i) {
                return ResultUtil.success("编辑分类成功");
            } else {
                return ResultUtil.error("编辑分类失败");
            }
        }
    
        @PostMapping("/delete")
        @ResponseBody
        public ResponseVo delete(Integer id) {
            if (CollUtil.isNotEmpty(categoryService.selectByPid(id))) {
                return ResultUtil.error("该分类下存在子分类!");
            }
            return deleteBatch(new Integer[]{id});
        }
    
        @PostMapping("/batch/delete")
        @ResponseBody
        public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[] ids) {
            int i = categoryService.deleteBatch(ids);
            if (i > 0) {
                return ResultUtil.success("删除分类成功");
            } else {
                return ResultUtil.error("删除分类失败");
            }
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111

    package com.puboot.module.admin.controller;

    import com.puboot.module.admin.service.BizCategoryService;
    import com.puboot.module.admin.service.SysConfigService;
    import lombok.AllArgsConstructor;
    import org.springframework.http.HttpStatus;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**

    • 统一错误跳转页面,如403,404,500

    */
    @Controller
    @RequestMapping(“/error”)
    @AllArgsConstructor
    public class ErrorController {

    private final SysConfigService sysConfigService;
    private final BizCategoryService bizCategoryService;
    
    /**
     * shiro无权限时进入
     *
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/403")
    public String noPermission(HttpServletRequest request, HttpServletResponse response, Model model) {
        response.setStatus(HttpStatus.FORBIDDEN.value());
        return "error/403";
    }
    
    @RequestMapping("/404")
    public String notFund(HttpServletRequest request, HttpServletResponse response, Model model) {
        return "error/404";
    }
    
    @RequestMapping("/500")
    public String sysError(HttpServletRequest request, HttpServletResponse response, Model model) {
        return "error/500";
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    }

  • 相关阅读:
    Java - SpringBoot整合JWT
    史诗级外挂,肝完这份 MQ+ 分布式事务套餐,其实阿里 P8 你也值得
    合并区间【贪心算法】
    如何使用SpringBoot处理全局异常
    idea创建包时无法分层
    【茫茫架构路】1. Class File字节码文件解析
    照片+制作照片书神器,效果太棒了!
    MySQL索引
    2023华为杯数学建模D题第三问——区域双碳目标情景设计样例
    基于篇章结构的英文作文自动评分方法(学习笔记)
  • 原文地址:https://blog.csdn.net/qq_35334787/article/details/127955519