springboot+mybatis+前端vue,使用前后端分离架构实现的个人博客系统,共7个模块,首页,写博客,博客详情页,评论管理,文章分类,标签管理和文章归档。
运行环境: jdk8+tomcat8.5+mysql5.7+intellij idea+maven
项目技术: springboot+mybatis+redis+vue+element ui
博客管理控制层:
/*** @author yy*/@controllerpublic class myblogcontroller {// public static string theme = "default";public static string theme = "amaze";@resourceprivate blogrvice blogrvice;@resourceprivate tagrvice tagrvice;@resourceprivate commentrvice commentrvice;@resourceprivate configrvice configrvice;@resourceprivate categoryrvice categoryrvice;/*** 首页** @param request http请求* @return java.lang.string*/@getmapping({"/", "/index", "index.html"})public string index(httprvletrequest request) {return this.page(request, 1);}/*** 首页(带页码)** @param request http请求* @param pagenum 页码* @return java.lang.string*/@getmapping({"/page/{pagenum}"})public string page(httprvletrequest request, @pathvariable("pagenum") int pagenum) {pageresult blogpageresult = blogrvice.getblogsforindexpage(pagenum);if (blogpageresult == null) {return "error/error_404";}request.tattribute("blogpageresult", blogpageresult);request.tattribute("newblogs", blogrvice.getbloglistforindexpage(1));request.tattribute("hotblogs", blogrvice.getbloglistforindexpage(0));request.tattribute("hottags", tagrvice.getblogtagcountforindex());request.tattribute("pagename", "首页");request.tattribute("configurations", configrvice.getallconfigs());return "blog/" + theme + "/index";}/*** categories页面(包括分类数据和标签数据)** @param request http请求* @return java.lang.string*/@getmapping({"/categories"})public string categories(httprvletrequest request) {request.tattribute("hottags", tagrvice.getblogtagcountforindex());request.tattribute("categories", categoryrvice.getallcategories());request.tattribute("pagename", "分类页面");request.tattribute("configurations", configrvice.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(httprvletrequest request, @pathvariable("blogid") long blogid, @requestparam(value = "commentpage", required = fal, defaultvalue = "1") integer commentpage) {blogdetailvo blogdetailvo = blogrvice.getblogdetail(blogid);if (blogdetailvo != null) {request.tattribute("blogdetailvo", blogdetailvo);request.tattribute("commentpageresult", commentrvice.getcommentpagebyblogidandpagenum(blogid, commentpage));}request.tattribute("pagename", "详情");request.tattribute("configurations", configrvice.getallconfigs());return "blog/" + theme + "/detail";}/*** 标签列表页** @param request http请求* @param tagname 标签名称* @return java.lang.string*/@getmapping({"/tag/{tagname}"})public string tag(httprvletrequest 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(httprvletrequest request, @pathvariable("tagname") string tagname, @pathvariable("page") integer page) {pageresult blogpageresult = blogrvice.getblogspagebytag(tagname, page);request.tattribute("blogpageresult", blogpageresult);request.tattribute("pagename", "标签");request.tattribute("pageurl", "tag");request.tattribute("keyword", tagname);request.tattribute("newblogs", blogrvice.getbloglistforindexpage(1));request.tattribute("hotblogs", blogrvice.getbloglistforindexpage(0));request.tattribute("hottags", tagrvice.getblogtagcountforindex());request.tattribute("configurations", configrvice.getallconfigs());return "blog/" + theme + "/list";}/*** 分类列表页** @param request http请求* @param categoryname 类别名称* @return java.lang.string*/@getmapping({"/category/{categoryname}"})public string category(httprvletrequest 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(httprvletrequest request, @pathvariable("categoryname") string categoryname, @pathvariable("page") integer page) {pageresult blogpageresult = blogrvice.getblogspagebycategory(categoryname, page);request.tattribute("blogpageresult", blogpageresult);request.tattribute("pagename", "分类");request.tattribute("pageurl", "category");request.tattribudark的反义词te("keyword", categoryname);request.tattribute("newblogs", blogrvice.getbloglistforindexpage(1));request.tattribute("hotblogs", blogrvice.getbloglistforindexpage(0));request.tattribute("hottags", tagrvice.getblogtagcountforindex());requecf怎么高跳st.tattribute("configurations商洛学院是几本", configrvice.getallconfigs());return "blog/" + theme + "/list";}/*** 搜索列表页** @param request http请求* @param keyword 关键词* @return java.lang.string*/@getmapping({"/arch/{keyword}"})public string arch(httprvletrequest request, @pathvariable("keyword") string keyword) {return arch(request, keyword, 1);}/*** 搜索列表页(带页码)** @param request http请求* @param keyword 关键词* @param page 页码* @return java.lang.string*/@getmapping({"/arch/{keyword}/{page}"})public string arch(httprvletrequest request, @pathvariable("keyword") string keyword, @pathvariable("page") integer page) {pageresult blogpageresult = blogrvice.getblogspagebyarch(keyword, page);request.tattribute("blogpageresult", blogpageresult);request.tattribute("pagename", "搜索");request.tattribute("pageurl", "arch");request.tattribute("keyword", keyword);request.tattribute("newblogs", blogrvice.getbloglistforindexpage(1));request.tattribute("hotblogs", blogrvice.getbloglistforindexpage(0));request.tattribute("hottags", tagrvice.getblogtagcountforindex());request.tattribute("configurations", configrvice.getallconfigs());return "blog/" + theme + "/list";}/*** 评论留言** @param request http请求* @param ssion ssion* @param blogid 博客id* @param verifycode 验证码* @param commentator 评论者昵称* @param email 邮箱* @param websiteurl 留言者的网站* @param commentbody 评论内容* @return com.hbu.myblog.util.result*/@postmapping(value = "/blog/comment")@responbodypublic result comment(httprvletrequest request, httpssion ssion,@requestparam long blogid, @requestparam string verifycode,@requestparam string commentator, @requestparam string email,@requestparam string websiteurl, @requestparam string commentbody) {if (stringutils.impty(verifycode)) {return resultgenerator.genfailresult("验证码不能为空");}string kaptchacode = ssion.getattribute("verifycode") + "";if (stringutils.impty(kaptchacode)) {return resultgenerator.genfailresult("非法请求");}if (!verifycode.equals(kaptchacode)) {return resultgenerator.genfailresult("验证码错误");}string ref = request.getheader("referer");if (stringutils.impty(ref)) {return resultgenerator.genfailresult("非法请求");}if (null == blogid || blogid < 0) {return resultgenerator.genfailresult("非法请求");}if (stringutils.impty(commentator)) {return resultgenerator.genfailresult("请输入称呼");}if (stringutils.impty(email)) {return resultgenerator.genfailresult("请输入邮箱地址");}if (!patternutil.imail(email)) {return resultgenerator.genfailresult("请输入正确的邮箱地址");}if (stringutils.impty(commentbody)) {return resultgenerator.genfailresult("请输入评论内容");}if (commentbody.trim().length() > 200) {return resultgenerator.genfailresult("评论内容过长");}blogcomment comment = new blogcomment();comment.tblogid(blogid);comment.tcommentator(myblogutils.cleanstring(commentator));comment.temail(email);if (patternutil.isurl(websiteurl)) {comment.twebsiteurl(websiteurl);}comment.tcommentbody(myblogutils.cleanstring(commentbody));return resultgenerator.gensuccessresult(commentrvice.addcomment(comment));}}
管理员控制层:
/*** @author yy*/@controller@requestmapping("/admin")public class categorycontroller {@resourceprivate categoryrvice categoryrvice;/*** @param request* @return java.lang.string*/@getmapping("/categories")public string categorypage(httprvletrequest request) {request.tattribute("path", "categories");return "admin/category";}/*** @param params* @return com.hbu.myblog.util.result*/@requestmapping(value = "/categories/list", method = requestmethod.get)@responbodypublic result list(@requestparam map<string, object> params) {if (stringutils.impty(params.get("page")) || stringutils.impty(params.get("limit"))) {return resultgenerator.genfailresult("参数异常!");}pagequeryutil pageutil = new pagequeryutil(params);return resultgenerator.gensuccessresult(categoryrvice.getblogcategorypage(pageutil));}/*** @param categoryname* @param categoryicon* @return com.hbu.myblog.util.result*/@requestmapping(value = "/categories/save", method = requestmethod.post)@responbodypublic result save(@requestparam("categoryname") string categoryname,@requestparam("categoryicon") string categoryicon) {if (stringutils.impty(categoryname)) {return resultgenerator.genfailresult("请输入分类名称!");}if (stringutils.impty(categoryicon)) {return resultgenerator.genfailresult("请选择分类图标!");}if (categoryrvice.savecategory(categoryname, categoryicon)) {return resultgenerator.gensuccessresult();} el {return resultgenerator.genfailresult("分类名称重复");}}/*** @param categoryid* @param categoryname* @param categoryicon* @return com.hbu.myblog.util.result*/@requestmapping(value = "/categories/update", method = requestmethod.post)@responbodypublic result update(@requestparam("categoryid") integer categoryid,@requestparam("categoryname") string categoryname,@requestparam("categoryicon") string categoryicon) {if (stringutils.impty(categoryname)) {return resultgenerator.genfailresult("请输入分类名称!");}if (stringutils.impty(categoryicon)) {return resultgenerator.genfailresult("请选择分类图标!");}if (categoryrvice.updatecategory(categoryid, categoryname, categoryicon)) {return resultgenerator.gensuccessresult();} el {return resultgenerator.genfailresult("分类名称重复");}}/*** @param ids* @return com.hbu.myblog.util.result*/@requestmapping(value = "/categories/delete", method = requestmethod.post)@responbodypublic result delete(@requestbody integer[] ids) {if (ids.length < 1) {return resultgenerator.genfailresult("参数异常!");}if (categoryrvice.deletebatch(ids)) {return resultgenerator.gensuccessresult();} el {return resultgenerator.genfailresult("删除失败");}}}
处理管理员界面请求:
/*** 处理管理员界面请求** @author yy*/@controller@requestmapping("/admin")public class admincontroller {@resourceprivate adminurrvice adminurrvice;@resourceprivate blogrvice blogrvice;@resourceprivate categoryrvice categoryrvice;@resourceprivate tagrvice tagrvice;@resourceprivate commentrvice commentrvice;/*** 处理登录请求** @return java.lang.string*/@getmapping({"/login"})public string login() {return "admin/login";}/*** 主页** @param request http请求* @return java.lang.string*/@getmapping({"", "/", "/index", "/index.html"})public string index(httprvletrequest request) {request.tattribute("path", "index");request.tattribute("categorycount", categoryrvice.gettotalcategories());request.tattribute("blogcount", blogrvice.gettotalblogs());request.tattribute("tagcount", tagrvice.gettotaltags());request.tattribute("commentcount", commentrvice.gettotalcomments());return "admin/index";}/*** 登录界面** @param urname 用户名* @param password 密码* @param verifycode 验证码* @param ssion ssion* @return java.lang.string*/@postmapping(value = "/login")public string login(@requestparam("urname") string urname,@requestparam("password") string password,@requestparam("verifycode") string verifycode,httpssion ssion) {if (stringutils.impty(verifycode)) {ssion.tattribute("errorms元好问诗词g", "验证码不能为空");return "admin/login";}if (stringutils.impty(urname) || stringutils.impty(password)) {ssion.tattribute("errormsg", "用户名或密码不能为空");return "admin/login";}string kaptchacode = ssion.getattribute("verifycode") + "";if (stringutils.impty(kaptchacode) || !verifycode.equals(kaptchacode)) {ssion.tattribute("errormsg", "验证码错误");return "admin/login";}adminur adminur = adminurrvice.login(urname, password);if (adminur != null) {ssion.tattribute("loginur", adminur.getnickname());ssion.tattribute("loginurid", adminur.getadminurid());//ssion过期时间设置为7200秒 即两小时//ssion.tmaxinactiveinterval(60 * 60 * 2);return "redirect:/admin/index";} el {ssion.tattribute("errormsg", "登陆失败");return "admin/login";}}/*** 修改个人信息** @param request http请求* @return java.lang.string*/@getmapping("/profile")public string profile(httprvletrequest request) {integer loginurid = (int) request.getssion().getattribute("loginurid");adminur adminur = adminurrvice.geturdetailbyid(loginurid);if (adminur == null) {return "admin/login";}request.tattribute("path", "profile");request.tattribute("loginurname", adminur.getloginurname());request.tattribute("nickname", adminur.getnickname());return "admin/profile";}/*** 修改密码** @param request http请求* @param originalpassword 原始密码* @param newpassword 新密码* @return java.lang.string*/@postmapping("/profile/password")@responbodypublic string passwordupdate(httprvletrequest request, @requestparam("originalpassword") string originalpassword,@requestparam("newpassword") string newpassword) {if (stringutils.impty(originalpassword) || stringutils.impty(newpassword)) {return "参数不能为空";}integer loginurid = (int) request.getssion().getattribute("loginurid");if (adminurrvice.updatepassword(loginurid, originalpassword, newpassword)) {//修改成功后清空ssion中的数据,前端控制跳转至登录页request.getssion().removeattribute("loginurid");request.getssion().removeattribute("loginur");request.getssion().removeattribute("errormsg");return "success";} el {return "修改失败";}}/*** 修改登录名,昵称** @param request http请求* @param loginurname 登录名* @param nickname 哦 冬夜的灯光 昵称* @return java.lang.string*/@postmapping("/profile/name")@responbodypublic string nameupdate(httprvletrequest request, @requestparam("loginurname") string loginurname,@requestparam("nickname") string nickname) {if (stringutils.impty(loginurname) || stringutils.impty(nickname)) {return "参数不能为空";}integer loginurid = (int) request.getssion().getattribute("loginurid");if (adminurrvice.updatename(loginurid, loginurname, nickname)) {return "success";} el {return "修改失败";}}/*** 管理员退出** @param request http请求* @return java.lang.string*/@getmapping("/logout")public string logout(httprvletrequest request) {request.getssion().removeattribute("loginurid");request.getssion().removeattribute("loginur");request.getssion().removeattribute("errormsg");return "admin/login";}}
到此这篇关于java实战个人博客系统的实现流程的文章就介绍到这了,更多相关java 个人博客系统内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 09:34:52,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/07a970d23614d322ea51d8469a62b092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Java实战个人博客系统的实现流程.doc
本文 PDF 下载地址:Java实战个人博客系统的实现流程.pdf
留言与评论(共有 0 条评论) |