Java毕业设计实战之生活旅行分享平台的实现
程序员文章站
2022-06-15 14:18:36
一、项目运行环境配置:jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclispe,sts都支持)项目技术:springbo...
一、项目运行
环境配置:
jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclispe,sts都支持)
项目技术:
springboot+ springmvc + jpa+ jsp + html+ javascript + jquery + ajax + maven等等
评论业务控制器:
/** * 评论控制器 * @author yy * */ @restcontroller @requestmapping("/comment") public class commentcontroller { @resource private commentservice commentservice; @resource private articleservice articleservice; @resource private replyservice replyservice; /** * 分页查询评论 * @param comment * @param page * @param pagesize * @return */ @requestmapping("/list") public map<string, object> commentlist(comment comment, @requestparam(value = "page", required = false) integer page, @requestparam(value = "pagesize", required = false) integer pagesize) { list<comment> commentlist = commentservice.list(comment, null, null, page - 1, pagesize, null); long total = commentservice.getcount(comment, null, null, null); int totalpage = (int) (total % pagesize == 0 ? total / pagesize : total / pagesize + 1); map<string, object> resultmap = new hashmap<string, object>(); resultmap.put("totalpage", totalpage); resultmap.put("data", commentlist); return resultmap; } /** * 分页查询评论 * @param page * @param pagesize * @return */ @requestmapping("/massagelist") public map<string, object> massagelist(@requestparam(value = "page", required = false) integer page, @requestparam(value = "pagesize", required = false) integer pagesize) { list<comment> commentlist = commentservice.massagelist(page - 1, pagesize); long total = commentservice.getcount2(); int totalpage = (int) (total % pagesize == 0 ? total / pagesize : total / pagesize + 1); map<string, object> resultmap = new hashmap<string, object>(); resultmap.put("totalpage", totalpage); resultmap.put("data", commentlist); return resultmap; } /** * 添加评论 * @title: add * @param comment 评论实体 * @return 参数说明 * @return map<string,object> 返回类型 * @throws */ @requestmapping("/add") public map<string, object> add(comment comment, httpsession session) { user currentuser = (user) session.getattribute("user"); map<string, object> resultmap = new hashmap<string, object>(); comment.setcommentdate(new date()); comment.setuser(currentuser); commentservice.add(comment); if (comment.getarticle() != null) { articleservice.increasecomment(comment.getarticle().getarticleid()); } resultmap.put("comment", comment); resultmap.put("success", true); return resultmap; } }
回复业务控制器:
/** * 回复控制器 * @author yy * */ @restcontroller @requestmapping("/reply") public class replycontroller { @resource private replyservice replyservice; /** * 获取回复 * @param reply * @return */ @requestmapping("/list") public map<string, object> replylist(reply reply) { list<reply> replylist = replyservice.list(reply); map<string, object> resultmap = new hashmap<string, object>(); resultmap.put("data", replylist); return resultmap; } /** * 添加回复 * @param reply * @return */ @requestmapping("/add") public map<string, object> add(reply reply, httpsession session) { user currentuser = (user) session.getattribute("user"); map<string, object> resultmap = new hashmap<string, object>(); reply.setreplydate(new date()); reply.setuser(currentuser); replyservice.add(reply); resultmap.put("reply", reply); resultmap.put("success", true); return resultmap; } }
管理员业务控制器:
/** * 管理员控制器 * @author yy * */ @restcontroller @requestmapping("/admin") public class admincontroller { @value("${md5salt}") private string salt; // md5加密盐 @resource private adminservice adminservice; @resource private userservice userservice; @resource private articleservice articleservice; @resource private classifyservice classifyservice; /** * 后台管理员登录验证 * @param admin * @param request * @return */ @requestmapping("/login") public modelandview login(admin admin, httpservletrequest request) { modelandview mav = new modelandview(); httpsession session = request.getsession(); try { admin resultuser = adminservice.findbyusernameandpassword(admin.getusername(), admin.getpassword()); if (resultuser == null) { mav.addobject("errorinfo", "用户名或者密码错误!"); mav.setviewname("/login"); } else { session.setattribute("adminuser", resultuser); // 统计用户总数 long usercount = userservice.getcount(); // 统计今天注册 long userregcount = userservice.gettodayregistcount(new user(), "1", "1"); // 统计今日登录 long userlogcount = userservice.getcount(new user(), "1", "1"); // 统计笔记总数 long artcount = articleservice.getcount(); // 统计笔记分类 long classcount = classifyservice.getcount(); session.setattribute("usercount", usercount); session.setattribute("userregcount", userregcount); session.setattribute("userlogcount", userlogcount); session.setattribute("artcount", artcount); session.setattribute("classcount", classcount); mav.addobject("success", true); mav.setviewname("/admin/index"); } } catch (exception e) { // 用户名密码错误 e.printstacktrace(); mav.addobject("admin", admin); mav.addobject("errorinfo", "用户名或者密码错误!"); mav.setviewname("/login"); } return mav; } /** * 查看个人信息 * * @return */ @requestmapping("viewperson") public modelandview viewperson(httpservletrequest request) { admin admin = (admin) request.getsession().getattribute("adminuser"); modelandview mav = new modelandview(); admin u = adminservice.findbyid(admin.getadminid()); mav.addobject("user", u); mav.setviewname("/admin/adminviewperson"); return mav; } /** * 保存用户信息 * * @param user * @return */ @requestmapping("/save") public modelandview save(admin user) { modelandview mav = new modelandview(); adminservice.save(user); mav.setviewname("/admin/index"); return mav; } }
用户业务控制器:
/** * 用户控制器 * */ @restcontroller @requestmapping("/admin/user") public class useradmincontroller { @resource private userservice userservice; @value("${md5salt}") private string salt; // md5加密盐 /** * 根据id查找用户 * @param userid * @return */ @requestmapping("/findbyid") public map<string, object> findbyid(integer userid) { map<string, object> resultmap = new hashmap<string, object>(); user user = userservice.findbyid(userid); resultmap.put("errorno", 0); resultmap.put("data", user); return resultmap; } /** * 分页查询用户 * @param user * @param registrationdates * @param page * @param limit * @return */ @requestmapping("/list") public map<string, object> list(user user, @requestparam(value = "latelylogintimes", required = false) string latelylogintimes, @requestparam(value = "page", required = false) integer page, @requestparam(value = "pagesize", required = false) integer pagesize) { string s_bregistrationdate = null; // 开始时间 string s_eregistrationdate = null; // 结束时间 if (stringutil.isnotempty(latelylogintimes)) { string[] strs = latelylogintimes.split(" - "); // 拆分时间段 s_bregistrationdate = strs[0]; s_eregistrationdate = strs[1]; } list<user> userlist = userservice.list(user, s_bregistrationdate, s_eregistrationdate, page - 1, pagesize); long total = userservice.getcount(user, s_bregistrationdate, s_eregistrationdate); map<string, object> resultmap = new hashmap<string, object>(); resultmap.put("errorno", 0); resultmap.put("data", userlist); resultmap.put("total", total); return resultmap; } @requestmapping("/delete") public map<string, object> delete(integer userid) { map<string, object> resultmap = new hashmap<string, object>(); userservice.delete(userid); resultmap.put("errorno", 0); return resultmap; } /** * 取消关注 * @param request * @param userid * @return */ @requestmapping("/removefocususer") public modelandview removefocususer(httpservletrequest request, string userid) { modelandview mav = new modelandview(); user user = (user) request.getsession().getattribute("user");// 当前登录用户 string userids = user.getuserids(); list<string> templist = arrays.aslist(userids.split(",")); list<string> lineidlist = new arraylist<>(templist); lineidlist.remove(userid); string ret = stringutils.join(lineidlist, ","); user.setuserids(ret); userservice.save(user); mav.setviewname("redirect:/viewfocususer"); return mav; } /** * 关注用户 * @param request * @param userid * @return */ @requestmapping("/addfocususer") public modelandview addfocususer(httpservletrequest request, string userid) { modelandview mav = new modelandview(); user user = (user) request.getsession().getattribute("user");// 当前登录用户 string userids = user.getuserids(); list<string> templist = arrays.aslist(userids.split(",")); list<string> lineidlist = new arraylist<>(templist); lineidlist.add(userid); string ret = stringutils.join(lineidlist, ","); user.setuserids(ret); userservice.save(user); mav.setviewname("redirect:/viewfocususer"); return mav; } @requestmapping("/addfocususer/{userid}") public modelandview addfocususer(@pathvariable(value = "userid", required = false) integer userid, httpsession session) { modelandview mav = new modelandview(); user user = (user) session.getattribute("user");// 当前登录用户 string userids = user.getuserids(); list<string> templist = new arraylist<>(); if (userids != null) { templist = arrays.aslist(userids.split(",")); } list<string> lineidlist = new arraylist<>(templist); lineidlist.add(userid.tostring()); string ret = stringutils.join(lineidlist, ","); user.setuserids(ret); userservice.save(user); mav.setviewname("redirect:/viewfocususer"); return mav; } /** * 取消收藏 * @param request * @param userid * @return */ @requestmapping("/removecollection") public modelandview removecollection(httpservletrequest request, string artid) { modelandview mav = new modelandview(); user user = (user) request.getsession().getattribute("user");// 当前登录用户 string artids = user.getarticleids(); list<string> templist = arrays.aslist(artids.split(",")); list<string> lineidlist = new arraylist<>(templist); lineidlist.remove(artid); string ret = stringutils.join(lineidlist, ","); user.setarticleids(ret); userservice.save(user); mav.setviewname("redirect:/viewcollection"); return mav; } /** * 收藏 * @param request * @param userid * @return */ @requestmapping("/addcollection") public modelandview addcollection(httpservletrequest request, string artid) { modelandview mav = new modelandview(); user user = (user) request.getsession().getattribute("user");// 当前登录用户 string artids = user.getarticleids(); list<string> templist = arrays.aslist(artids.split(",")); list<string> lineidlist = new arraylist<>(templist); lineidlist.add(artid); string ret = stringutils.join(lineidlist, ","); user.setarticleids(ret); userservice.save(user); mav.setviewname("redirect:/viewcollection"); return mav; } }
到此这篇关于java毕业设计实战之生活旅行分享平台的实现的文章就介绍到这了,更多相关java 生活旅行分享平台内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!