欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

程序员文章站 2022-03-23 10:06:18
一、项目简述本系统功能包括: 基于vue + springboo痼j后端分离项目个人博客系统,注册 登录,首页展示,喜爰图书展示,后台图书维护,个人文 章展示,后台文章上传等等。二、项目运行环境配置:...

一、项目简述

本系统功能包括: 基于vue + springboo痼j后端分离项目个人博客系统,注册 登录,首页展示,喜爰图书展示,后台图书维护,个人文 章展示,后台文章上传等等。

二、项目运行

环境配置: jdk1.8 + tomcat8.5 + mysql + hbuilderx (webstorm也 行)+ eclispe (intellij idea,eclispe,myeclispe,sts都支 持)。

项目技术: springboot + maven + mybatis + vue + redis^k, b/s 模式+ maven等等。

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

Java 实战项目锤炼之朴素风格个人博客系统的实现流程

博客信息代码:

/**
 * 博客信息
 */
@controller
public 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;
 
    /**
     * 首页
     *
     * @param request http请求
     * @return java.lang.string
     */
    @getmapping({"/", "/index", "index.html"})
    public string index(httpservletrequest request) {
        return this.page(request, 1);
    }
 
    /**
     * 首页(带页码)
     *
     * @param request http请求
     * @param pagenum 页码
     * @return java.lang.string
     */
    @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";
    }
 
    /**
     * categories页面(包括分类数据和标签数据)
     *
     * @param request http请求
     * @return java.lang.string
     */
    @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";
    }
 
    /**
     * 详情页
     *
     * @param request     http请求
     * @param blogid      博客id
     * @param commentpage 评论页
     * @return java.lang.string
     */
    @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";
    }
 
    /**
     * 标签列表页
     *
     * @param request http请求
     * @param tagname 标签名称
     * @return java.lang.string
     */
    @getmapping({"/tag/{tagname}"})
    public string tag(httpservletrequest request, @pathvariable("tagname") string tagname) {
        return tag(request, tagname, 1);
    }
 
    /**
     * 标签列表页(带页码)
     *
     * @param request http请求
     * @param tagname 标签名称
     * @param page    页码
     * @return java.lang.string
     */
    @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";
    }
 
    /**
     * 分类列表页
     *
     * @param request      http请求
     * @param categoryname 类别名称
     * @return java.lang.string
     */
    @getmapping({"/category/{categoryname}"})
    public string category(httpservletrequest request, @pathvariable("categoryname") string categoryname) {
        return category(request, categoryname, 1);
    }
 
    /**
     * 分类列表页(带页码)
     *
     * @param request      http请求
     * @param categoryname 类别名称
     * @param page         页码
     * @return java.lang.string
     */
    @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";
    }
 
    /**
     * 搜索列表页
     *
     * @param request http请求
     * @param keyword 关键词
     * @return java.lang.string
     */
    @getmapping({"/search/{keyword}"})
    public string search(httpservletrequest request, @pathvariable("keyword") string keyword) {
        return search(request, keyword, 1);
    }
 
    /**
     * 搜索列表页(带页码)
     *
     * @param request http请求
     * @param keyword 关键词
     * @param page    页码
     * @return java.lang.string
     */
    @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";
    }
 
 
    /**
     * 评论留言
     *
     * @param request     http请求
     * @param session     session
     * @param blogid      博客id
     * @param verifycode  验证码
     * @param commentator 评论者昵称
     * @param email       邮箱
     * @param websiteurl  留言者的网站
     * @param commentbody 评论内容
     * @return com.hbu.myblog.util.result
     */
    @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));
    }
}

以上就是java 实战项目锤炼之朴素风格个人博客系统的实现流程的详细内容,更多关于java 博客系统的资料请关注其它相关文章!