iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >如何使用Java实现个人博客系统
  • 528
分享到

如何使用Java实现个人博客系统

2023-06-22 07:06:00 528人浏览 泡泡鱼
摘要

这篇文章将为大家详细讲解有关如何使用Java实现个人博客系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。运行环境: jdk8+Tomcat8.5+mysql5.7+IntelliJ idea+Maven

这篇文章将为大家详细讲解有关如何使用Java实现个人博客系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

运行环境: jdk8+Tomcat8.5+mysql5.7+IntelliJ idea+Maven

项目技术: SpringBoot+mybatis+redis+Vue+element ui

如何使用Java实现个人博客系统

如何使用Java实现个人博客系统

如何使用Java实现个人博客系统

如何使用Java实现个人博客系统

如何使用Java实现个人博客系统

如何使用Java实现个人博客系统

博客管理控制层:

  @Controllerpublic class MybloGController {    //    public static String theme = "default";    public static String theme = "amaze";    @Resource    private BlogService blogService;    @Resource    private TagService tagService;    @Resource    private CommentService commentService;    @Resource    private ConfigService configService;    @Resource    private CateGoryService categoryService;         @GetMapping({"/", "/index", "index.html"})    public String index(httpservletRequest request) {        return this.page(request, 1);    }         @GetMapping({"/page/{pageNum}"})    public String page(HttpServletRequest request, @PathVariable("pageNum") int pageNum) {        PageResult blogPageResult = blogService.getBlogsForIndexPage(pageNum);        if (blogPageResult == null) {            return "error/error_404";        }        request.setAttribute("blogPageResult", blogPageResult);        request.setAttribute("newBlogs", blogService.getBlogListForIndexPage(1));        request.setAttribute("hotBlogs", blogService.getBlogListForIndexPage(0));        request.setAttribute("hotTags", tagService.getBlogTagCountForIndex());        request.setAttribute("pageName", "首页");        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/index";    }         @GetMapping({"/categories"})    public String categories(HttpServletRequest request) {        request.setAttribute("hotTags", tagService.getBlogTagCountForIndex());        request.setAttribute("categories", categoryService.getAllCategories());        request.setAttribute("pageName", "分类页面");        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/category";    }         @GetMapping({"/blog/{blogId}", "/article/{blogId}"})    public String detail(HttpServletRequest request, @PathVariable("blogId") Long blogId, @RequestParam(value = "commentPage", required = false, defaultValue = "1") Integer commentPage) {        BlogDetailVO blogDetailVO = blogService.getBlogDetail(blogId);        if (blogDetailVO != null) {            request.setAttribute("blogDetailVO", blogDetailVO);            request.setAttribute("commentPageResult", commentService.getCommentPageByBlogIdAndPageNum(blogId, commentPage));        }        request.setAttribute("pageName", "详情");        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/detail";    }         @GetMapping({"/tag/{tagName}"})    public String tag(HttpServletRequest request, @PathVariable("tagName") String tagName) {        return tag(request, tagName, 1);    }         @GetMapping({"/tag/{tagName}/{page}"})    public String tag(HttpServletRequest request, @PathVariable("tagName") String tagName, @PathVariable("page") Integer page) {        PageResult blogPageResult = blogService.getBlogsPageByTag(tagName, page);        request.setAttribute("blogPageResult", blogPageResult);        request.setAttribute("pageName", "标签");        request.setAttribute("pageUrl", "tag");        request.setAttribute("keyWord", tagName);        request.setAttribute("newBlogs", blogService.getBlogListForIndexPage(1));        request.setAttribute("hotBlogs", blogService.getBlogListForIndexPage(0));        request.setAttribute("hotTags", tagService.getBlogTagCountForIndex());        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/list";    }         @GetMapping({"/category/{categoryName}"})    public String category(HttpServletRequest request, @PathVariable("categoryName") String categoryName) {        return category(request, categoryName, 1);    }         @GetMapping({"/category/{categoryName}/{page}"})    public String category(HttpServletRequest request, @PathVariable("categoryName") String categoryName, @PathVariable("page") Integer page) {        PageResult blogPageResult = blogService.getBlogsPageByCategory(categoryName, page);        request.setAttribute("blogPageResult", blogPageResult);        request.setAttribute("pageName", "分类");        request.setAttribute("pageUrl", "category");        request.setAttribute("keyword", categoryName);        request.setAttribute("newBlogs", blogService.getBlogListForIndexPage(1));        request.setAttribute("hotBlogs", blogService.getBlogListForIndexPage(0));        request.setAttribute("hotTags", tagService.getBlogTagCountForIndex());        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/list";    }         @GetMapping({"/search/{keyword}"})    public String search(HttpServletRequest request, @PathVariable("keyword") String keyword) {        return search(request, keyword, 1);    }         @GetMapping({"/search/{keyword}/{page}"})    public String search(HttpServletRequest request, @PathVariable("keyword") String keyword, @PathVariable("page") Integer page) {        PageResult blogPageResult = blogService.getBlogsPageBySearch(keyword, page);        request.setAttribute("blogPageResult", blogPageResult);        request.setAttribute("pageName", "搜索");        request.setAttribute("pageUrl", "search");        request.setAttribute("keyword", keyword);        request.setAttribute("newBlogs", blogService.getBlogListForIndexPage(1));        request.setAttribute("hotBlogs", blogService.getBlogListForIndexPage(0));        request.setAttribute("hotTags", tagService.getBlogTagCountForIndex());        request.setAttribute("configurations", configService.getAllConfigs());        return "blog/" + theme + "/list";    }          @PostMapping(value = "/blog/comment")    @ResponseBody    public Result comment(HttpServletRequest request, HttpSession session,                          @RequestParam Long blogId, @RequestParam String verifyCode,                          @RequestParam String commentator, @RequestParam String email,                          @RequestParam String WEBsiteUrl, @RequestParam String commentBody) {        if (StringUtils.isEmpty(verifyCode)) {            return ResultGenerator.genFailResult("验证码不能为空");        }        String kaptchaCode = session.getAttribute("verifyCode") + "";        if (StringUtils.isEmpty(kaptchaCode)) {            return ResultGenerator.genFailResult("非法请求");        }        if (!verifyCode.equals(kaptchaCode)) {            return ResultGenerator.genFailResult("验证码错误");        }        String ref = request.getHeader("Referer");        if (StringUtils.isEmpty(ref)) {            return ResultGenerator.genFailResult("非法请求");        }        if (null == blogId || blogId < 0) {            return ResultGenerator.genFailResult("非法请求");        }        if (StringUtils.isEmpty(commentator)) {            return ResultGenerator.genFailResult("请输入称呼");        }        if (StringUtils.isEmpty(email)) {            return ResultGenerator.genFailResult("请输入邮箱地址");        }        if (!PatternUtil.isEmail(email)) {            return ResultGenerator.genFailResult("请输入正确的邮箱地址");        }        if (StringUtils.isEmpty(commentBody)) {            return ResultGenerator.genFailResult("请输入评论内容");        }        if (commentBody.trim().length() > 200) {            return ResultGenerator.genFailResult("评论内容过长");        }        BlogComment comment = new BlogComment();        comment.setBlogId(blogId);        comment.setCommentator(MyBlogUtils.cleanString(commentator));        comment.setEmail(email);        if (PatternUtil.isURL(websiteUrl)) {            comment.setWebsiteUrl(websiteUrl);        }        comment.setCommentBody(MyBlogUtils.cleanString(commentBody));        return ResultGenerator.genSuccessResult(commentService.addComment(comment));    }}

管理员控制层:

 @Controller@RequestMapping("/admin")public class CategoryController {     @Resource    private CategoryService categoryService;         @GetMapping("/categories")    public String categoryPage(HttpServletRequest request) {        request.setAttribute("path", "categories");        return "admin/category";    }         @RequestMapping(value = "/categories/list", method = RequestMethod.GET)    @ResponseBody    public Result list(@RequestParam Map<String, Object> params) {        if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {            return ResultGenerator.genFailResult("参数异常!");        }        PageQueryUtil pageUtil = new PageQueryUtil(params);        return ResultGenerator.genSuccessResult(categoryService.getBlogCategoryPage(pageUtil));    }         @RequestMapping(value = "/categories/save", method = RequestMethod.POST)    @ResponseBody    public Result save(@RequestParam("categoryName") String categoryName,                       @RequestParam("categoryIcon") String categoryIcon) {        if (StringUtils.isEmpty(categoryName)) {            return ResultGenerator.genFailResult("请输入分类名称!");        }        if (StringUtils.isEmpty(categoryIcon)) {            return ResultGenerator.genFailResult("请选择分类图标!");        }        if (categoryService.saveCategory(categoryName, categoryIcon)) {            return ResultGenerator.genSuccessResult();        } else {            return ResultGenerator.genFailResult("分类名称重复");        }    }          @RequestMapping(value = "/categories/update", method = RequestMethod.POST)    @ResponseBody    public Result update(@RequestParam("categoryId") Integer categoryId,                         @RequestParam("categoryName") String categoryName,                         @RequestParam("categoryIcon") String categoryIcon) {        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("分类名称重复");        }    }          @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("删除失败");        }    } }

处理管理员界面请求:

 @Controller@RequestMapping("/admin")public class AdminController {     @Resource    private AdminUserService adminUserService;    @Resource    private BlogService blogService;    @Resource    private CategoryService categoryService;    @Resource    private TagService tagService;    @Resource    private CommentService commentService;          @GetMapping({"/login"})    public String login() {        return "admin/login";    }         @GetMapping({"", "/", "/index", "/index.html"})    public String index(HttpServletRequest request) {        request.setAttribute("path", "index");        request.setAttribute("categoryCount", categoryService.getTotalCategories());        request.setAttribute("blogCount", blogService.getTotalBlogs());        request.setAttribute("tagCount", tagService.getTotalTags());        request.setAttribute("commentCount", commentService.getTotalComments());        return "admin/index";    }         @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", "验证码不能为空");            return "admin/login";        }        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {            session.setAttribute("errorMsg", "用户名或密码不能为空");            return "admin/login";        }        String kaptchaCode = session.getAttribute("verifyCode") + "";        if (StringUtils.isEmpty(kaptchaCode) || !verifyCode.equals(kaptchaCode)) {            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";        }    }         @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";        }        request.setAttribute("path", "profile");        request.setAttribute("loginUserName", adminUser.getLoginUserName());        request.setAttribute("nickName", adminUser.getNickName());        return "admin/profile";    }         @PostMapping("/profile/password")    @ResponseBody    public String passwordUpdate(HttpServletRequest request, @RequestParam("originalPassword") String originalPassword,                                 @RequestParam("newPassword") String newPassword) {        if (StringUtils.isEmpty(originalPassword) || StringUtils.isEmpty(newPassword)) {            return "参数不能为空";        }        Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");        if (adminUserService.updatePassword(loginUserId, originalPassword, newPassword)) {            //修改成功后清空session中的数据,前端控制跳转至登录页            request.getSession().removeAttribute("loginUserId");            request.getSession().removeAttribute("loginUser");            request.getSession().removeAttribute("errorMsg");            return "success";        } else {            return "修改失败";        }    }         @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 "修改失败";        }    }         @GetMapping("/logout")    public String logout(HttpServletRequest request) {        request.getSession().removeAttribute("loginUserId");        request.getSession().removeAttribute("loginUser");        request.getSession().removeAttribute("errorMsg");        return "admin/login";    }}

关于“如何使用Java实现个人博客系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

--结束END--

本文标题: 如何使用Java实现个人博客系统

本文链接: https://www.lsjlt.com/news/303354.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 如何使用Java实现个人博客系统
    这篇文章将为大家详细讲解有关如何使用Java实现个人博客系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。运行环境: jdk8+tomcat8.5+mysql5.7+IntelliJ IDEA+maven...
    99+
    2023-06-22
  • PHP如何实现个人博客系统
    要实现一个个人博客系统,可以使用PHP来构建。以下是一个简单的步骤:1. 设计数据库结构:首先,设计数据库表来存储博客的相关信息,如...
    99+
    2023-08-24
    PHP
  • 如何使用PHP实现个人博客
    要使用PHP实现个人博客,您可以按照以下步骤进行操作:1. 创建数据库:在MySQL中创建一个数据库,用于存储博客相关的数据,如文章...
    99+
    2023-08-24
    PHP
  • Java实战个人博客系统的实现流程
    springboot+mybatis+前端vue,使用前后端分离架构实现的个人博客系统,共7个模块,首页,写博客,博客详情页,评论管理,文章分类,标签管理和文章归档。 运行环境: j...
    99+
    2024-04-02
  • Javaweb如何实现完整个人博客系统流程
    这篇文章主要讲解了“Javaweb如何实现完整个人博客系统流程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Javaweb如何实现完整个人博客系统流程”吧!项目的基本流程1.准备工作pom....
    99+
    2023-06-29
  • 如何使用博客系统搭建个人网站
    如何使用博客系统搭建个人网站,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。博客,又译为网络日志、部落格或部落阁等,是一种通常由个人管理、不定期张贴新的文章的网站。博客上的文章通...
    99+
    2023-06-12
  • PythonDjango实现个人博客系统的搭建
    目录1.需要安装Python和Django2.创建一个Django项目3.创建一个Django应用程序4.配置数据库5.创建模型6.创建视图7.创建模板8.创建URL9.更新主URL...
    99+
    2023-05-17
    Python Django搭建个人博客系统 Python Django 博客系统 Python Django 系统
  • Javaweb实现完整个人博客系统流程
    目录一、项目背景二、项目功能三、项目的基本流程1.准备工作2.数据库设计3.准备前端页面4.实现前端匹配的Servlet所需功能5.项目难点一、项目背景 在学习完JavaWeb相关知...
    99+
    2024-04-02
  • SpringBoot前后端分离实现个人博客系统
    目录一、项目简介二、环境介绍三、系统展示四、核心代码展示五、项目总结一、项目简介 本项目使用springboot+mybatis+前端vue,使用前后端分离架构实现的个人博客系统,共...
    99+
    2024-04-02
  • 如何使用GitLab搭建个人博客
    近年来,个人博客已成为程序员、设计师等人群不可或缺的一部分。然而,建立博客对于新手来说,并不是一件容易的事情。有许多选择,例如用WordPress、Hugo、Jekyll等技术,但这些方案多少有些麻烦。本文将介绍如何使用GitLab来搭建个...
    99+
    2023-10-22
  • Java个人博客系统--基于Springboot的设计与实现+测试
    目录 一、项目概述 应用技术 接口实现:  数据库定义: 数据库建表: 博客表数据库相关操作: 添加项⽬公共模块 加密MD5 页面展示:http://121.41.168.121:8080/blog_login.html  项目源码:h...
    99+
    2023-09-04
    java spring boot 开发语言
  • 如何使用MySQL和Python实现一个简单的博客系统
    要使用MySQL和Python实现一个简单的博客系统,可以按照以下步骤进行:1. 安装MySQL数据库和Python的MySQL库:...
    99+
    2023-10-20
    MySQL
  • php个人博客系统怎么搭建
    要搭建一个 PHP 个人博客系统,你需要以下步骤:1. 选择一个合适的 PHP 框架,比如 Laravel、CodeIgniter、...
    99+
    2023-06-14
    php个人博客 php
  • 基于PHP如何实现个人博客网站
    要基于PHP实现个人博客网站,需要进行以下几个步骤:1. 选择合适的开发框架:PHP有很多开发框架可供选择,例如Laravel、Co...
    99+
    2023-08-14
    PHP
  • nodejs如何实现个人博客的后台登陆
    这篇文章主要介绍nodejs如何实现个人博客的后台登陆,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!定义后台路径访问这个路径进入后台页面 http://localhost:8888/...
    99+
    2024-04-02
  • 基于PHP实现个人博客网站
    目录一、运行展示二、功能说明三、核心代码讲解1、创建数据库2、初始化数据3、登录验证4、用户注册5、发表博客6、更新博客7、删除博客8、发表评论9、修改密码10、修改昵称11、管理员...
    99+
    2024-04-02
  • Java 实战项目锤炼之朴素风格个人博客系统的实现流程
    一、项目简述 本系统功能包括: 基于vue + Springboo痼J后端分离项目个人博客系统,注册 登录,首页展示,喜爰图书展示,后台图书维护,个人文 章展示,后台文章上传等等。 ...
    99+
    2024-04-02
  • php个人博客网站怎么实现
    实现一个PHP个人博客网站需要以下步骤:1. 确定网站的需求和功能,比如博客列表、文章阅读、评论、分类、标签、搜索等。2. 设计网站...
    99+
    2023-06-13
    php个人博客 php
  • Ubuntu如何搭建WordPress个人博客
    这篇文章主要介绍了Ubuntu如何搭建WordPress个人博客的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Ubuntu如何搭建WordPress个人博客文章都会有所收获,下面我们一起来看看吧。准备 LAMP...
    99+
    2023-07-04
  • 怎么使用Hexo搭建个人博客
    Hexo是一种快速、简单且强大的静态博客框架,它可用于搭建个人博客或网站。与其他CMS(内容管理系统)不同,例如WordPress或Joomla,Hexo生成静态文件,这使得网站的访问速度更快,更安全。本文将向你介绍使用Hexo搭建个人博客...
    99+
    2023-10-22
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作