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


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

    开发工具:IDEA,数据库mysql

    技术:springboot+mybatis-plus+redis

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

    前台截图:

     

     

     

    后台截图:

     

     

     

     

     

     

     

     

    1. package com.puboot.module.admin.controller;
    2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
    3. import com.puboot.common.util.CoreConst;
    4. import com.puboot.module.admin.model.BizCategory;
    5. import com.puboot.module.admin.model.User;
    6. import com.puboot.module.admin.service.BizCategoryService;
    7. import com.puboot.module.admin.service.BizStatisticService;
    8. import com.puboot.module.admin.service.PermissionService;
    9. import com.puboot.module.admin.service.SysConfigService;
    10. import lombok.AllArgsConstructor;
    11. import org.apache.shiro.SecurityUtils;
    12. import org.springframework.stereotype.Controller;
    13. import org.springframework.ui.Model;
    14. import org.springframework.web.bind.annotation.GetMapping;
    15. import org.springframework.web.bind.annotation.RequestMapping;
    16. import java.util.List;
    17. import java.util.Map;
    18. /**
    19. * 后台管理页面跳转控制器
    20. *
    21. * @version V1.0
    22. */
    23. @Controller
    24. @AllArgsConstructor
    25. public class AdminRenderController {
    26. private final BizCategoryService categoryService;
    27. private final SysConfigService sysConfigService;
    28. private final PermissionService permissionService;
    29. private final BizStatisticService statisticService;
    30. /**
    31. * 后台首页
    32. */
    33. @RequestMapping("/admin")
    34. public String index(Model model) {
    35. model.addAttribute("menuTree", permissionService.selectMenuTreeByUserId(((User) SecurityUtils.getSubject().getPrincipal()).getUserId()));
    36. return CoreConst.ADMIN_PREFIX + "index/index";
    37. }
    38. /**
    39. * 工作台
    40. */
    41. @GetMapping("/workdest")
    42. public String workdest(Model model) {
    43. model.addAttribute("statistic", statisticService.indexStatistic());
    44. return CoreConst.ADMIN_PREFIX + "index/dashboard";
    45. }
    46. /**
    47. * 用户列表入口
    48. */
    49. @GetMapping("/users")
    50. public String userList() {
    51. return CoreConst.ADMIN_PREFIX + "user/list";
    52. }
    53. /**
    54. * 角色列表入口
    55. */
    56. @GetMapping("/roles")
    57. public String roleList() {
    58. return CoreConst.ADMIN_PREFIX + "role/list";
    59. }
    60. /**
    61. * 权限列表入口
    62. */
    63. @GetMapping("/permissions")
    64. public String permissionList() {
    65. return CoreConst.ADMIN_PREFIX + "permission/list";
    66. }
    67. /**
    68. * 在线用户入口
    69. */
    70. @GetMapping("/online/users")
    71. public String onlineUsers() {
    72. return CoreConst.ADMIN_PREFIX + "onlineUsers/list";
    73. }
    74. /**
    75. * 网站基本信息
    76. *
    77. * @param model
    78. */
    79. @GetMapping("/siteinfo")
    80. public String siteinfo(Model model) {
    81. Map map = sysConfigService.selectAll();
    82. model.addAttribute("siteinfo", map);
    83. return CoreConst.ADMIN_PREFIX + "site/siteinfo";
    84. }
    85. /**
    86. * 友情链接
    87. */
    88. @GetMapping("/links")
    89. public String links() {
    90. return CoreConst.ADMIN_PREFIX + "link/list";
    91. }
    92. /**
    93. * 分类
    94. */
    95. @GetMapping("/categories")
    96. public String categories() {
    97. return CoreConst.ADMIN_PREFIX + "category/list";
    98. }
    99. /**
    100. * 标签
    101. */
    102. @GetMapping("/tags")
    103. public String tags() {
    104. return CoreConst.ADMIN_PREFIX + "tag/list";
    105. }
    106. /**
    107. * 文章
    108. *
    109. * @param model
    110. */
    111. @GetMapping("/articles")
    112. public String articles(Model model) {
    113. List categories = categoryService.list(Wrappers.lambdaQuery().eq(BizCategory::getStatus, CoreConst.STATUS_VALID));
    114. model.addAttribute("categories", categories);
    115. return CoreConst.ADMIN_PREFIX + "article/list";
    116. }
    117. /**
    118. * 评论
    119. */
    120. @GetMapping("/comments")
    121. public String comments() {
    122. return CoreConst.ADMIN_PREFIX + "comment/list";
    123. }
    124. /**
    125. * 主题
    126. */
    127. @GetMapping("themes")
    128. public String themes() {
    129. return CoreConst.ADMIN_PREFIX + "theme/list";
    130. }
    131. }

     

    package com.puboot.module.admin.controller;
    
    import com.alibaba.fastjson.JSON;
    import com.baomidou.mybatisplus.core.metadata.IPage;
    import com.puboot.common.util.CoreConst;
    import com.puboot.common.util.Pagination;
    import com.puboot.common.util.PushArticleUtil;
    import com.puboot.common.util.ResultUtil;
    import com.puboot.enums.SysConfigKey;
    import com.puboot.module.admin.model.BizArticle;
    import com.puboot.module.admin.model.BizCategory;
    import com.puboot.module.admin.model.BizTags;
    import com.puboot.module.admin.model.User;
    import com.puboot.module.admin.service.*;
    import com.puboot.module.admin.vo.ArticleConditionVo;
    import com.puboot.module.admin.vo.BaiduPushResVo;
    import com.puboot.module.admin.vo.base.PageResultVo;
    import com.puboot.module.admin.vo.base.ResponseVo;
    import lombok.AllArgsConstructor;
    import org.apache.shiro.SecurityUtils;
    import org.springframework.cache.annotation.CacheEvict;
    import org.springframework.stereotype.Controller;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.*;
    
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * 后台文章管理
     *
    
     * @version V1.0
    
     */
    @Controller
    @RequestMapping("article")
    @AllArgsConstructor
    public class ArticleController {
    
        private final BizArticleService articleService;
        private final BizArticleTagsService articleTagsService;
        private final BizCategoryService categoryService;
        private final BizTagsService tagsService;
        private final SysConfigService configService;
    
        @PostMapping("list")
        @ResponseBody
        public PageResultVo loadArticle(ArticleConditionVo articleConditionVo, Integer pageNumber, Integer pageSize) {
            articleConditionVo.setSliderFlag(true);
            IPage page = new Pagination<>(pageNumber, pageSize);
            List articleList = articleService.findByCondition(page, articleConditionVo);
            return ResultUtil.table(articleList, page.getTotal());
        }
    
        /*文章*/
        @GetMapping("/add")
        public String addArticle(Model model) {
            BizCategory bizCategory = new BizCategory();
            bizCategory.setStatus(CoreConst.STATUS_VALID);
            List bizCategories = categoryService.selectCategories(bizCategory);
            List tags = tagsService.list();
            model.addAttribute("categories", bizCategories);
            model.addAttribute("tags", tags);
            BizArticle bizArticle = new BizArticle().setTags(new ArrayList<>()).setOriginal(1).setSlider(0).setTop(0).setRecommended(0).setComment(1);
            model.addAttribute("article", bizArticle);
            return CoreConst.ADMIN_PREFIX + "article/publish";
        }
    
        @PostMapping("/add")
        @ResponseBody
        @Transactional
        @CacheEvict(value = "article", allEntries = true)
        public ResponseVo add(BizArticle bizArticle, Integer[] tag) {
            try {
                User user = (User) SecurityUtils.getSubject().getPrincipal();
                bizArticle.setUserId(user.getUserId());
                bizArticle.setAuthor(user.getNickname());
                BizArticle article = articleService.insertArticle(bizArticle);
                articleTagsService.insertList(tag, article.getId());
                return ResultUtil.success("保存文章成功");
            } catch (Exception e) {
                return ResultUtil.error("保存文章失败");
            }
        }
    
        @GetMapping("/edit")
        public String edit(Model model, Integer id) {
            BizArticle bizArticle = articleService.selectById(id);
            model.addAttribute("article", bizArticle);
            BizCategory bizCategory = new BizCategory();
            bizCategory.setStatus(CoreConst.STATUS_VALID);
            List bizCategories = categoryService.selectCategories(bizCategory);
            model.addAttribute("categories", bizCategories);
            List sysTags = tagsService.list();
            /*方便前端处理回显*/
            List aTags = new ArrayList<>();
            List sTags = new ArrayList<>();
            boolean flag;
            for (BizTags sysTag : sysTags) {
                flag = false;
                for (BizTags articleTag : bizArticle.getTags()) {
                    if (articleTag.getId().equals(sysTag.getId())) {
                        BizTags tempTags = new BizTags();
                        tempTags.setId(sysTag.getId());
                        tempTags.setName(sysTag.getName());
                        aTags.add(tempTags);
                        sTags.add(tempTags);
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    sTags.add(sysTag);
                }
            }
            bizArticle.setTags(aTags);
            model.addAttribute("tags", sTags);
            return CoreConst.ADMIN_PREFIX + "article/publish";
        }
    
        @PostMapping("/edit")
        @ResponseBody
        @CacheEvict(value = "article", allEntries = true)
        public ResponseVo edit(BizArticle article, Integer[] tag) {
            articleService.updateById(article);
            articleTagsService.removeByArticleId(article.getId());
            articleTagsService.insertList(tag, article.getId());
            return ResultUtil.success("编辑文章成功");
        }
    
        @PostMapping("/delete")
        @ResponseBody
        public ResponseVo delete(Integer id) {
            return deleteBatch(new Integer[]{id});
        }
    
        @PostMapping("/batch/delete")
        @ResponseBody
        public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[] ids) {
            int i = articleService.deleteBatch(ids);
            if (i > 0) {
                return ResultUtil.success("删除文章成功");
            } else {
                return ResultUtil.error("删除文章失败");
            }
        }
    
        @PostMapping("/batch/push")
        @ResponseBody
        public ResponseVo pushBatch(@RequestParam("urls[]") String[] urls) {
            try {
                String url = configService.selectAll().get(SysConfigKey.BAIDU_PUSH_URL.getValue());
                BaiduPushResVo baiduPushResVo = JSON.parseObject(PushArticleUtil.postBaidu(url, urls), BaiduPushResVo.class);
                if (baiduPushResVo.getNotSameSite() == null && baiduPushResVo.getNotValid() == null) {
                    return ResultUtil.success("推送文章成功");
                } else {
                    return ResultUtil.error("推送文章失败", baiduPushResVo);
                }
            } catch (Exception e) {
                return ResultUtil.error("推送文章失败,请检查百度推送接口!");
            }
    
        }
    }
    
  • 相关阅读:
    【走方格的方案数】
    五子棋(C语言实现)
    java计算机毕业设计基于ssm的基于android的家庭理财系统
    力扣 hot100 最长连续序列 哈希去重 双指针
    Linux线程1
    题目:2706.购买两块巧克力
    Remote Sensing投稿经验分享
    【短文】在Windows显示所有当前打开的连接和监听的端口
    Neuron Newsletter 2022-08|新增 Beckhoff ADS、OPC DA 驱动
    算法训练第六十二天
  • 原文地址:https://blog.csdn.net/weixin_42899150/article/details/127955455