jdk1.8 + tomcat8.5 + mysql + hbuilderx(webstorm也行)+ eclispe(intellij idea,eclispe,myeclispe,sts都支持)。
springboot + maven + mybatis+ vue 等等组成,b/s模式 + maven管理等等。
系统控制器:
/*** 系统控制器* @author yy**/@requestmapping("/system")@controllerpublic class systemcontroller {@autowiredprivate operaterlogrvice operaterlogrvice;@autowiredprivate urrvice urrvice;@autowiredprivate datababakrvice datababakrvice;@autowiredprivate staffrvice staffrvice;@autowiredprivate orderauthrvice orderauthrvice;private logger log = loggerfactory.getlogger(systemcontroller.class);/*** 登录页面* @param model* @return*/@reque投资自己stmapping(value="/login",method=requestmethod.get)public string login(model model){model.addattribute("logintypes", logintype.values());return "admin/system/login";}/*** 用户登录提交表单处理方法* @param request* @param cpacha* @return*/@requestmapping(value="/login",method=requestmethod.post)@responbodypublic result<boolean> login(httprvletrequest request,string urname,string password,string cpacha,integer type){if(stringutils.impty(urname)){return result.error(codemsg.admin_urname_empty);}if(stringutils.impty(password)){return result.error(codemsg.admin_password_empty);}//表示实体信息合法,开始验证验证码是否为空if(stringutils.impty(cpacha)){return result.error(codemsg.cpacha_empty);}//说明验证码不为空,从ssion里获取验证码object attribute = request.getssion().getattribute("admin_login");if(attribute == null){return result.error(codemsg.ssion_expired);}//表示ssion未失效,进一步判断用户填写的验证码是否正确if(!cpacha.equalsignoreca(attribute.tostring())){return result.error(codemsg.cpacha_error);}if(type == logintype.administrator.getcode()){//表示验证码正确,开始查询数据库,检验密码是否正确ur findbyurname = urrvice.findbyurname(urname);//判断是否为空if(findbyurname == null){return result.error(codemsg.admin_urname_no_exist);}//表示用户存在,进一步对比密码是否正确if(!findbyurname.getpassword().equals(password)){return result.error(codemsg.admin_password_error);}//表示密码正确,接下来判断用户状态是否可用if(findbyurname.getstatus() == ur.admin_ur_status_unable){return result.error(codemsg.admin_ur_unable);}//检查用户所属角色状态是否可用if(findbyurname.getrole() == null || findbyurname.getrole().getstatus() == role.admin_role_status_unable){return result.error(codemsg.admin_ur_role_unable);}//检查用户所属角色的权限是否存在if(findbyurname.getrole().getauthorities() == null || findbyurname.getrole().getauthorities().size() == 0){return result.error(codemsg.admin_ur_role_authorites_empty);}//检查一切符合,可以登录,将用户信息存放至ssionrequest.getssion().tattribute(ssionconstant.ssion_ur_login_key, findbyurname);request.getssion().tattribute("logintype",type);//销毁ssion中的验证码request.getssion().tattribute("admin_login", null);//将登陆记录写入日志库operaterlogrvice.add("用户【"+urname+"】于【" + stringutil.getformatterdate(new date(), "yyyy-mm-dd hh:mm:ss") + "】登录系统!");log.info("用户成功登录,ur = " + findbyurname);}el{staff byjobnumber = staffrvice.findbynameandisstatus(urname);//判断是否为空if(byjobnumber == null){return result.error(codemsg.admin_urname_no_exist);}//表示用户存在,进一步对比密码是否正确if(!byjobnumber.getpassword().equals(password)){return result.error(codemsg.admin_password_error);}//检查用户所属角色状态是否可用if(byjobnumber.getrole() == null || byjobnumber.getrole().getstatus() == role.admin_role_status_unable){return result.error(codemsg.admin_ur_role_unable);}//检查用户所属角色的权限是否存在if(byjobnumber.getrole().getauthorities() == null || byjobnumber.getrole().getauthorities().size() == 0){return result.error(codemsg.admin_ur_role_authorites_empty);}//检查一切符合,可以登录,将用户信息存放至ssionrequest.getssion().tattribute(ssionconstant.ssion_staff_login_key, byjobnumber);request.getssion().tattribute("logintype",type);//销毁ssion中的验证码request.getssion().tattribute("admin_login", null);//将登陆记录写入日志库operaterlogrvice.add("用户【"+urname+"】于【" + stringutil.getformatterdate(new date(), "yyyy-mm-dd hh:mm:ss") + "】登录系统!");log.info("员工成功登录,ur = " + byjobnumber);}return result.success(true);}/*** 登录成功后的系统主页* @param model* @return*/@requestmapping(value="/index")public string index(model model){model.addattribute("operatorlogs", operaterlogrvice.findlastestlog(10));model.addattribute("urtotal", urrvice.total());model.addattribute("operatorlogtotal", operaterlogrvice.total());model.addattribute("datababackuptotal", datababakrvice.total());model.addattribute("onlineurtotal", ssionlistener.onlineurcount);return "admin/system/index";}/*** 注销登录* @return*/@requestmapping(value="/logout")public string logout(){integer logintype = (integer) ssionutil.get("logintype");if(logintype == logintype.administrator.getcode()){ur loginedur = ssionutil.getloginedur();if(loginedur != null){ssionutil.t(ssionconstant.ssion_ur_login_key, null);}}el if(logintype == logintype.staff.getcode()){staff loginedstaff = ssionutil.getloginedstaff();if(loginedstaff != null){ssionutil.t(ssionconstant.ssion_staff_login_key,null);}}return "redirect:login";}/*** 无权限提示页面* @return*/@requestmapping(value="/no_right")public string noright(){return "admin/system/no_right";}/*** 修改用户个人信息* @return*/@requestmapping(value="/update_urinfo",method=requestmethod.get)public string updateurinfo(){return "admin/system/update_urinfo";}/*** 修改个人信息保存* @param ur* @return*/@requestmapping(value="/update_urinfo",method=requestmethod.post)public string updateurinfo(ur ur){ur loginedur = ssionutil.getloginedur();loginedur.temail(ur.getemail());loginedur.tmobile(ur.getmobile());loginedur.theadpic(ur.getheadpic());//首先保存到数据库urrvice.save(loginedur);//更新ssion里的值ssionutil.t(ssionconstant.ssion_ur_login_key, loginedur);return "redirect:update_urinfo";}/*** 修改密码页面* @return*/@requestmapping(value="/update_pwd",method=requestmethod.get)public string updatepwd(){return "admin/system/update_pwd";}/*** 修改密码表单提交* @param oldpwd* @param newpwd* @return*/@requestmapping(value="/update_pwd",method=requestmethod.post)@responbodypublic result<boolean> updatepwd(@requestparam(name="oldpwd",required=true)string oldpwd,@requestparam(name="newpwd",required=true)string newpwd){integer logintype = (integer) ssionutil.get("logintype");if(logintype == logintype.administrator.getcode()){ur loginedur = ssionutil.getloginedur();if(!loginedur.getpassword().equals(oldpwd)){return result.error(codemsg.admin_ur_update_pwd_error);}if(stringutils.impty(newpwd)){return result.error(codemsg.admin_ur_update_pwd_empty);}if(newpwd.length()<4 || newpwd.length()>32){return result.error(codemsg.admin_ur_pwd_length_error);}loginedur.tpassword(newpwd);//保存数据库urrvice.save(loginedur);//更新ssionssionutil.t(ssionconstant.ssion_ur_login_key, loginedur);}el{staff loginedstaff = ssionutil.getloginedstaff();staff staff = staffrvice.find(loginedstaff.getid());if(!staff.getpassword().equals(oldpwd)){return result.error(codemsg.admin_ur_update_pwd_error);}if(stringutils.impty(newpwd)){return result.error(codemsg.admin_ur_update_pwd_empty);}staff.tpassword(newpwd);codemsg codemsg = validateentityutil.validate(staff);if (codemsg.getcode() != codemsg.success.getcode()){return result.error(codemsg);}loginedstaff.tpassword(newpwd);//保存数据库staffrvice.save(loginedstaff);//更新ssionssionutil.t(ssionconstant.ssion_staff_login_key, loginedstaff);}return result.success(true);}/*** 日志管理列表* @param model* @param operaterlog* @param pagebean* @return*/@requestmapping(value="/operator_log_list")public string operatorloglist(model model,operaterlog operaterlog,pagebean<operaterlog> pagebean){model.addattribute("pagebean", operaterlogrvice.findlist(operaterlog, pagebean));model.addattribute("operator", operaterlog.getoperator());model.addattribute("title", "日志列表");return "admin/system/operator_log_list";}/*** 验证订单* @param ordersn* @param phone* @return*/@requestmapping(value="/auth_order",method=requestmethod.post)@responbodypublic result<boolean> authorder(@requestparam(name="ordersn",required=true)string ordersn,@requestparam(name="phone",required=true)string phone){orderauth orderauth = new orderauth();orderauth.tmac(stringutil.getmac());orderauth.tordersn(ordersn);orderauth.tphone(phone);orderauthrvice.save(orderauth);appconfig.order_auth = 1;return result.success(true);}/*** 删除操作日志,可删除多个* @param ids* @return*/@requestmapping(value="/delete_operator_log",method=requestmethod.post)@responbodypublic result<boolean> delete(string ids){if(!stringutils.impty(ids)){string[] splitids = ids.split(",");for(string id : splitids){operaterlogrvice.delete(long.valueof(id));}}return result.success(true);}/*** 清空整个日志* @return*/@requestmapping(value="/delete_all_operator_log",method=requestmethod.post)@responbodypublic result<boolean> deleteall(){operaterlogrvice.deleteall();return result.success(true);}}
后台用户管理控制器:
/*** 后台用户管理控制器* @author yy**/@requestmapping("/admin/ur")@controllerpublic class urcontroller {@autowiredprivate urrvice urrvice;@autowiredprivate rolervice rolervice;@autowiredprivate operaterlogrvice operaterlogrvice;/*** 用户列表页面* @param model* @param ur* @param pagebean* @return*/@requestmapping(value="/list")public string list(model model,ur ur,pagebean<ur> pagebean){model.addattribute("title", "用户列表");model.addattribute("urname", ur.geturname());model.addattribute("pagebean", urrvice.findlist(ur, pagebean));return "admin/ur/list";}/*** 新增用户页面* @param model* @return*/@requestmapping(value="/add",method=requestmethod.get)public string add(model model){model.addattribute("roles", rolervice.findall());return "admin/ur/add";}/*** 用户添加表单提交处理* @param ur* @return*/@requestmapping(value="/add",method=requestmethod.post)@responbodypublic result<boolean> add(ur ur){//用统一验证实体方法验证是否合法codemsg validate = validateentityutil.validate(ur);if(validate.getcode() != codemsg.success.getcode()){return result.error(validate);}if(ur.getrole() == null || ur.getrole().getid() == null){return result.error(codemsg.admin_ur_role_empty);}//判断用户名是否存在if(urrvice.ixisturname(ur.geturname(), 0l)){return result.error(codemsg.admin_urname_exist);}//到这说明一切符合条件,进行数据库新增if(urrvice.save(ur) == null){return result.error(codemsg.admin_u_add_error);}operaterlogrvice.add("添加用户,用户名:" + ur.geturname());return result.success(true);}/*** 用户编辑页面* @param model* @return*/@requestmapping(value="/edit",method=requestmethod.get)public string edit(model model,@requestparam(name="id",required=true)long id){model.addattribute("roles", rolervice.findall());model.addattribute("ur", urrvice.find(id));return "admin/ur/edit";}/*** 编辑用户信息表单提交处理* @param ur* @return*/@requestmapping(value="/edit",method=requestmethod.post)@responbodypublic result<boolean> edit(ur ur){//用统一验证实体方法验证是否合法codemsg validate = validateentityutil.validate(ur);if(validate.getcode() != codemsg.success.getcode()){return result.error(validate);}if(ur.getrole() == null || ur.getrole().getid() == null){return result.error(codemsg.admin_ur_role_empty);}if(ur.getid() == null || ur.getid().longvalue() <= 0){return result.error(codemsg.admin_u_no_exist);}if(urrvice.ixisturname(ur.geturname(), ur.getid())){return result.error(codemsg.admin_urname_exist);}//到这说明一切符合条件,进行数据库保存ur findbyid = urrvice.find(ur.getid());//讲提交的用户信息指定字段复制到已存在的ur对象中,该方法会覆盖新字段内容beanutils.copyproperties(ur, findbyid, "id","createtime","updatetime");if(urrvice.save(findbyid) == null){return result.error(codemsg.admin_u_edit_error);}operaterlogrvice.add("编辑用户,用户名:" + ur.geturname());return result.success(true);}/*** 删除用户* @param id* @return*/@requestmapping(value="/delete",method=requestmethod.post)@responbodypublic result<boolean> delete(@requestparam(name="id",required=true)long id){try {urrvice.delete(id);} catch (exception e) {return result.error(codemsg.admin_u_delete_error);}operaterlogrvice.add("删除用户,用户id:" + id);return result.success(true);}}
后台角色管理控制器:
/*** 后台角色管理控制器* @author yy**/@requestmapping("/admin/role")@controllerpublic class rolecontroller {private logger log = loggerfactory.getlogger(rolecontroller.class);@autowiredprivate menurvice menurvice;@autowiredprivate operaterlogrvice operaterlogrvice;@autowiredprivate rolervice rolervice;/*** 分页搜索角色列表* @param model* @param role* @param pagebean* @return*/@requestmapping(value="/list")public string list(model model,role role,pagebean<role> pagebean){model.addattribute("title", "角色列表");model.addattribute("name", role.getname());model.addattribute("pagebean", rolervice.findbyname(role, pagebean));return "admin/role/list";}/*** 角色添加页面* @param model* @return*/@requestmapping(value="/add",method=requestmethod.get)public string add(model model){list<menu> findall = menurvice.findall();model.addattribute("topmenus",menuutil.gettopmenus(findall));model.addattribute("condmenus",menuutil.getcondmenus(findall));model.addattribute("thirdmenus",menuutil.getthirdmenus(findall));return "admin/role/add";}/*** 角色添加表单提交处理* @param role* @return*/@requestmapping(value="/add",method=requestmethod.post)@responbodypublic result<boolean> add(role role){//用统一验证实体方法验证是否合法code昆明理工大学排名msg validate = validateentityutil.validate(role);if(validate.getcode() != codemsg.success.getcode()){return result.error(validate);}if(rolervice.save(role) == null){return result.error(codemsg.admin_role_add_error);}log.info("添加角色【"+role+"】");operaterlogrvice.add("添加角色【"+role.getname()+"】");return result.success(true);}/*** 角色编辑页面* @param id* @param model* @return*/@requestmapping(val元旦晚会主题ue="/edit",method=requestmethod.get)public string edit(@requestparam(name="id",required=true)long id,model model){list<menu> findall = menurvice.findall();model.addattribute("topmenus",menuutil.gettopmenus(findall));model.addattribute("condmenus",menuutil.getcondmenus(findall));model.addattribute("thirdmenus",menuutil.getthirdmenus(findall));role role = rolervice.find(id);model.addattribute("role", role);model.addattribute("authorities",jsonarray.tojson(role.getauthorities()).tostring());return "admin/role/edit";}/*** 角色修改表单提交处理* @param request* @param role* @return*/@requestmapping(value="/edit",method=requestmethod.post)@responbodypublic result<boolean> edit(role role){//用统一验证实体方法验证亲爱的妈妈5韩国中字完整版是否合法codemsg validate = validateentityutil.validate(role);if(validate.getcode() != codemsg.success.getcode()){return result.error(validate);}role existrole = rolervice.find(role.getid());if(existrole == null){return result.error(codemsg.admin_role_no_exist);}existrole.tname(role.getname());existrole.tremark(role.getremark());existrole.tstatus(role.getstatus());existrole.tauthorities(role.getauthorities());if(rolervice.save(existrole) == null){return result.error(codemsg.admin_role_edit_error);}log.info("编辑角色【"+role+"】");operaterlogrvice.add("编辑角色【"+role.getname()+"】");return result.success(true);}/*** 删除角色* @param request* @param id* @return*/@requestmapping(value="delete",method=requestmethod.post)@responbodyp尺和厘米换算ublic result<boolean> delete(@requestparam(name="id",required=true)long id){try {rolervice.delete(id);} catch (exception e) {// todo: handle exceptionreturn result.error(codemsg.admin_role_delete_error);}log.info("编辑角色id【"+id+"】");operaterlogrvice.add("删除角色id【"+id+"】");return result.success(true);}}
到此这篇关于java毕业设计实战之食品溯源系统的实现的文章就介绍到这了,更多相关java 食品溯源系统内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 18:11:10,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/9e160d55672f10e311bff078d474f0cc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Java毕业设计实战之食品溯源系统的实现.doc
本文 PDF 下载地址:Java毕业设计实战之食品溯源系统的实现.pdf
留言与评论(共有 0 条评论) |