Java project: personal blog system (front and back end separation +java+vue+springboot+ssm+mysql+maven+redis)

Time:2022-6-1

Source code access: blog home page “resources” to download!

1、 Project brief

The functions of the system include: article display, popular articles, article classification, tag cloud user login comments, anonymous comment user comments, anonymous comment management, article publishing, article management, article data statistics, etc

2、 Project operation

Environment configuration: jdkl 8 + Tomcats . 5 + MySQL + hbuilderx (webstorm also works) + Eclispe (IntelliJ 10, three clispe, myeclispe, STS all support it).

Project technology: springboot + Maven + mybatis + Vue + redis, BIS mode + m Aven, etc., with Alipay sandbox environment and payment link code.

Java project: personal blog system (front and back end separation +java+vue+springboot+ssm+mysql+maven+redis)

Java project: personal blog system (front and back end separation +java+vue+springboot+ssm+mysql+maven+redis)

Java project: personal blog system (front and back end separation +java+vue+springboot+ssm+mysql+maven+redis)

Java project: personal blog system (front and back end separation +java+vue+springboot+ssm+mysql+maven+redis)

To process an administrator interface request:

/**
 *Processing administrator interface requests
 *
 */
@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;


    /**
     *Processing login requests
     *
     * @return java.lang.String
     */
    @GetMapping({"/login"})
    public String login() {
        return "admin/login";
    }

    /**
     *Home page
     *
     *@param request HTTP request
     * @return java.lang.String
     */
    @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";
    }

    /**
     *Login interface
     *
     *@param username username
     *@param password password
     *@param verifycode verification code
     * @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", "verification code cannot be empty");
            return "admin/login";
        }
        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
            session. SetAttribute ("errormsg", "user name or password cannot be empty");
            return "admin/login";
        }
        String kaptchaCode = session.getAttribute("verifyCode") + "";
        if (StringUtils.isEmpty(kaptchaCode) || !verifyCode.equals(kaptchaCode)) {
            session. SetAttribute ("errormsg", "verification code error");
            return "admin/login";
        }
        AdminUser adminUser = adminUserService.login(userName, password);
        if (adminUser != null) {
            session.setAttribute("loginUser", adminUser.getNickName());
            session.setAttribute("loginUserId", adminUser.getAdminUserId());
            //The session expiration time is set to 7200 seconds, or two hours
            //session.setMaxInactiveInterval(60 * 60 * 2);
            return "redirect:/admin/index";
        } else {
            session. SetAttribute ("errormsg", "login failed");
            return "admin/login";
        }
    }

    /**
     *Modify personal information
     *
     *@param request HTTP request
     * @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";
        }
        request.setAttribute("path", "profile");
        request.setAttribute("loginUserName", adminUser.getLoginUserName());
        request.setAttribute("nickName", adminUser.getNickName());
        return "admin/profile";
    }

    /**
     *Change password
     *
     *@param request HTTP request
     *@param originalpassword original password
     *@param newpassword new password
     * @return java.lang.String
     */
    @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 "the parameter cannot be empty.";
        }
        Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
        if (adminUserService.updatePassword(loginUserId, originalPassword, newPassword)) {
            //After the modification is successful, the data in the session is cleared, and the front-end control jumps to the login page
            request.getSession().removeAttribute("loginUserId");
            request.getSession().removeAttribute("loginUser");
            request.getSession().removeAttribute("errorMsg");
            return "success";
        } else {
            Return "modification failed";
        }
    }

    /**
     *Modify login name and nickname
     *
     *@param request HTTP request
     *@param loginusername login
     *@param nickname 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 "the parameter cannot be empty.";
        }
        Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
        if (adminUserService.updateName(loginUserId, loginUserName, nickName)) {
            return "success";
        } else {
            Return "modification failed";
        }
    }

    /**
     *Administrator exit
     *
     *@param request HTTP request
     * @return java.lang.String
     */
    @GetMapping("/logout")
    public String logout(HttpServletRequest request) {
        request.getSession().removeAttribute("loginUserId");
        request.getSession().removeAttribute("loginUser");
        request.getSession().removeAttribute("errorMsg");
        return "admin/login";
    }
}

Blog list controller:

/**
 *Blog list controller
 */
@Controller
@RequestMapping("/admin")
public class BlogController {

    @Resource
    private BlogService blogService;
    @Resource
    private CategoryService categoryService;

    /**
     *Blog list
     *
     *@param params parameter
     * @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 ("parameter exception!");
        }
        PageQueryUtil pageUtil = new PageQueryUtil(params);
        return ResultGenerator.genSuccessResult(blogService.getBlogsPage(pageUtil));
    }


    /**
     *@param request HTTP request
     * @return java.lang.String
     */
    @GetMapping("/blogs")
    public String list(HttpServletRequest request) {
        request.setAttribute("path", "blogs");
        return "admin/blog";
    }

    /**
     *@param request HTTP request
     * @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 request
     *@param blogid blog 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());
        return "admin/edit";
    }

    /**
     *Add article
     *
     *@param blogTitle article title
     *@param blogsummary summary summary
     *@param blogcategoryid category
     *@param blogtags tag
     *@param blogcontent content content
     *@param blogstatus draft, release
     *@param enablecomment can you comment
     * @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)) {
            return ResultGenerator. Genfailresult ("please enter the article title");
        }
        if (blogTitle.trim().length() > 150) {
            return ResultGenerator. Genfailresult ("the title is too long");
        }
        if (StringUtils.isEmpty(blogTags)) {
            return ResultGenerator. Genfailresult ("please enter the article label");
        }
        if (blogTags.trim().length() > 150) {
            return ResultGenerator. Genfailresult ("the label is too long");
        }
        if (blogSummary.trim().length() > 375) {
            return ResultGenerator. Genfailresult ("the summary is too long");
        }
        if (StringUtils.isEmpty(blogContent)) {
            return ResultGenerator. Genfailresult ("please enter the article content");
        }
        if (blogTags.trim().length() > 100000) {
            return ResultGenerator. Genfailresult ("the article content is too long");
        }
        Blog blog = new Blog();
        blog.setBlogTitle(blogTitle);
        blog.setBlogSummary(blogSummary);
        blog.setBlogCategoryId(blogCategoryId);
        blog.setBlogTags(blogTags);
        blog.setBlogContent(blogContent);
        blog.setBlogStatus(blogStatus);
        blog.setEnableComment(enableComment);
        String saveBlogResult = blogService.saveBlog(blog);
        if ("success".equals(saveBlogResult)) {
            return ResultGenerator. Gensuccessresult ("added successfully");
        } else {
            return ResultGenerator.genFailResult(saveBlogResult);
        }
    }

    /**
     *Modify article
     *
     *@param blogid article ID
     *@param blogTitle article title
     *@param blogsummary summary summary
     *@param blogcategoryid category
     *@param blogtags tag
     *@param blogcontent content content
     *@param blogstatus draft, release
     *@param enablecomment can you comment
     * @return com.hbu.myblog.util.Result
     */
    @PostMapping("/blogs/update")
    @ResponseBody
    public Result update(@RequestParam("blogId") Long blogId,
                         @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)) {
            return ResultGenerator. Genfailresult ("please enter the article title");
        }
        if (blogTitle.trim().length() > 150) {
            return ResultGenerator. Genfailresult ("the title is too long");
        }
        if (StringUtils.isEmpty(blogTags)) {
            return ResultGenerator. Genfailresult ("please enter the article label");
        }
        if (blogTags.trim().length() > 150) {
            return ResultGenerator. Genfailresult ("the label is too long");
        }
        if (blogSummary.trim().length() > 375) {
            return ResultGenerator. Genfailresult ("the summary is too long");
        }
        if (StringUtils.isEmpty(blogContent)) {
            return ResultGenerator. Genfailresult ("please enter the article content");
        }
        if (blogTags.trim().length() > 100000) {
            return ResultGenerator. Genfailresult ("the article content is too long");
        }
        Blog blog = new Blog();
        blog.setBlogId(blogId);
        blog.setBlogTitle(blogTitle);
        blog.setBlogSummary(blogSummary);
        blog.setBlogCategoryId(blogCategoryId);
        blog.setBlogTags(blogTags);
        blog.setBlogContent(blogContent);
        blog.setBlogStatus(blogStatus);
        blog.setEnableComment(enableComment);
        String updateBlogResult = blogService.updateBlog(blog);
        if ("success".equals(updateBlogResult)) {
            return ResultGenerator. Gensuccessresult ("modified successfully");
        } else {
            return ResultGenerator.genFailResult(updateBlogResult);
        }
    }


    /**
     *Delete article based on ID
     *
     *@param IDs to delete the article ID list
     * @return com.hbu.myblog.util.Result
     */
    @PostMapping("/blogs/delete")
    @ResponseBody
    public Result delete(@RequestBody Integer[] ids) {
        if (ids.length < 1) {
            return ResultGenerator. Genfailresult ("parameter exception!");
        }
        if (blogService.deleteBatch(ids)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator. Genfailresult ("delete failed");
        }
    }

}

Category information control layer:

/**
 *Category information control layer
 */
@Controller
@RequestMapping("/admin")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * @param request
     * @return java.lang.String
     */
    @GetMapping("/categories")
    public String categoryPage(HttpServletRequest request) {
        request.setAttribute("path", "categories");
        return "admin/category";
    }

    /**
     * @param params
     * @return com.hbu.myblog.util.Result
     */
    @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 ("parameter exception!");
        }
        PageQueryUtil pageUtil = new PageQueryUtil(params);
        return ResultGenerator.genSuccessResult(categoryService.getBlogCategoryPage(pageUtil));
    }

    /**
     * @param categoryName
     * @param categoryIcon
     * @return com.hbu.myblog.util.Result
     */
    @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 ("please enter the classification name!");
        }
        if (StringUtils.isEmpty(categoryIcon)) {
            return ResultGenerator. Genfailresult ("please select the classification icon!");
        }
        if (categoryService.saveCategory(categoryName, categoryIcon)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator. Genfailresult ("duplicate classification name");
        }
    }


    /**
     * @param categoryId
     * @param categoryName
     * @param categoryIcon
     * @return com.hbu.myblog.util.Result
     */
    @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 ("please enter the classification name!");
        }
        if (StringUtils.isEmpty(categoryIcon)) {
            return ResultGenerator. Genfailresult ("please select the classification icon!");
        }
        if (categoryService.updateCategory(categoryId, categoryName, categoryIcon)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator. Genfailresult ("duplicate classification name");
        }
    }


    /**
     * @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 ("parameter exception!");
        }
        if (categoryService.deleteBatch(ids)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator. Genfailresult ("delete failed");
        }
    }

}

Source code access: blog home page “resources” to download!