首页 > 作文

Java实现茶叶售卖商城系统(java+SSM+JSP+EasyUi+mysql)

更新时间:2023-04-04 02:12:19 阅读: 评论:0

目录
前言实现效果主要代码用户管理控制层商品管理服务类订单控制层

前言

这是一个应用ssm框架的项目,前端页面整洁清晰。该系统有两个角色,一个是普通用户,另一个是管理员。

普通用户具有注册、登录、查看商品、添加购物车、添加商品收藏、下订单、商品评价、用户地址管理等等功能。

管理员具有登录、管理用户信息、管理商品信息、管理商品活动信息、管理订单信息、管理用户评论信息的等等功能。

应用技术:jsp + ssm + easyui

运行环境:eclip/idea + mysql5.7 + tomcat8.5 + jdk1.8

实现效果

主要代码

用户管理控制层

@webrvlet("/frontstage_urrvlet")public class urrvlet extends httprvlet {urrvice rvice = new urrvice(); @overrideprotected void rvice(httprvletrequest req, httprvletrespon resp) throws rvletexception, ioexception {string action = req.getparameter("action"); switch (action) {ca "login":login(req, resp);break;ca "checkurnamerepeat":checkurnamerepeat(req, resp);break;ca "register":register(req, resp);break;ca "logout":logout(req, resp);break;ca "checkoldpassword":checkoldpassword(req, resp);break;ca "modifypassword":modifypassword(req, resp);break;}} public void login(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");string urname = req.getparameter("urname");string password = req.getparameter("password");string captcha = req.getparameter("captcha");if (captcha != null) {captcha = captcha.toupperca();} // 先进行验证码验证string checkcode = (string) req.getssion().getattribute("checkcode_ssion"); try {// 将用户输入的验证码和 系统验证对比if (checkcode.equals(captcha)) {ur ur = rvice.geturbynameandpassword(urname, password);if (ur != null) {httpssion ssion = req.getssion();ssion.tattribute("u新东方厨师学费价目表r", ur);jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));} el {// 将错误信息封装在结果集中jsonresult result = jsonresult.errormsg("用户名或密码错误,请重试");// 以json的形式返回给前端resp.getwriter().println(jsonutil.javaobjecttojson(result));}} el {// 将错误信息封装在结果集中jsonresult result = jsonresult.errormsg("验证码输入错误,请重试");// 以json的形式返回给前端resp.getwriter().println(jsonutil.javaobjecttojson(result));}} catch (exception e) {e.printstacktrace();}} /** * 用户名重名检测 *  * @param req * @param resp */public void checkurnamerepeat(httprvletrequest req, httprvletrespon resp) {string urname = req.getparameter("urname"); if (urname != null) {int d = rvice.checkurnamerepeat(urname);try {if (d > 0) {jsonresult error = jsonresult.errormsg("");resp.getwriter().println(jsonutil.javaobjecttojson(error));} el {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}} catch (exception e) {e.printstacktrace();}}} /** * 用户注册 *  * @param req * @param resp * @throws ioexception  */public void register(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");ur ur = new ur();ur.turname(req.getparameter("urname"));ur.tpassword(req.getparameter("password"));ur.temail(req.getparameter("email"));ur.tphone(req.getparameter("phonenum"));ur.trole("ordinaryur");int d = rvice.addur(ur);try {if (d > 0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));} el {jsonresult error = jsonresult.errormsg("注册失败");resp.getwriter().println(jsonutil.javaobjecttojson(error));}} catch (exception e) {e.printstacktrace();}} /** * 退出登录 */public void logout(httprvletrequest req, httprvletrespon resp) {req.getssion().removeattribute("ur");try {resp.ndredirect("index.jsp");} catch (ioexception e) {e.printstacktrace();}} /** * 检查旧密码是否正确 ,在修改密码操作时使用 * @throws ioexception  */public void checkoldpassword(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");ur ur = (ur) req.getssion().getattribute("ur");string oldpassword = rvice.getpasswordbyid(ur.getid());system.out.print做好自己作文600字ln("旧密码:"+oldpassword);string password = req.getparameter("password");system.out.println("旧密码验证:"+password);try {if (!oldpassword.equals(password)) {jsonresult errormsg = jsonresult.errormsg("原始密码错误,请重新输入");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));} el {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}} catch (ioexception e) {e.printstacktrace();} } /** * 修改密码 * @throws ioexception  */public void modifypassword(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8"); string password = req.getparameter("newpassword");system.out.println("新密码:"+password);ur ur = (ur) req.getssion().getattribute("ur");int id = ur.getid();system.out.println("旧密码id"+id);int d = rvice.updatepasswordbyid(id, password);try {if (d > 0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));} el {  jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");  resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));} } catch (exception e) {e.printstacktrace();}} }

商品管理服务类

@webrvlet("/frontstage_goodsrvlet")public class goodsrvlet extends httprvlet{goodsrvice rvice = new goodsrvice();@overrideprotected void rvice(httprvletrequest req, httprvletrespon 那一些往事resp) throws rvletexception, ioexception {string action = req.getparameter("action");switch(action) {ca "findallgoods":findallgoods(req,resp);break;ca "findgoodsbyid":findgoodsbyid(req,resp);break;ca "findgoodsbytype":findgoodsbytype(req,resp);break;}}/** * 获取所有商品列表 * @param req * @param resp */public void findallgoods(httprvletrequest req, httprvletrespon resp) {map<string, list<goods>> allgoods = rvice.getallgoods();try {req.tattribute("allgoods", allgoods);req.getrequestdispatcher("/main.jsp").forward(req, resp);return;} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/** *根据类型获得商品列表  * @param req * @param resp */public void findgoodsbytype(httprvletrequest req, httprvletrespon resp) {string type = req.getparameter("type");string currentpage = req.getparameter("currentpage");pagebean pagebean = null;// 如果当前第几页currentpage 值为null,说明第一次跳转到此页面或者是要跳转到首页,则设定该值currentpage默认为1if(currentpage == null) {pagebean = rvice.getgoodsbytype(type, 4, 1);}el {pagebean = rvice.getgoodsbytype(type, 4, integer.parint(currentpage));}try {req.tattribute("pagebean", pagebean);req.tattribute("type", type);req.getrequestdispatcher("/product.jsp").forward(req, resp); } catch (exception e) {e.printstacktrace();}}/** * 获取商品的详细信息 * @param req * @param resp */public void findgoodsbyid(httprvletrequest req, httprvletrespon resp) {int id =integer.parint(req.getparameter("id"));goods goodsinfo = rvice.getgoodsinfobyid(id);try {req.tattribute("pro", goodsinfo);req.getrequestdispatcher("/productinfo_ur.jsp").forward(req, resp); } catch (exception e) {e.printstacktrace();}}}

订单控制层

@webrvlet("/backstage_ordersrvlet")public class ordersrvlet extends httprvlet{ordersrvice rvice = new ordersrvice();@overrideprotected void rvice(httprvletrequest req, httprvletrespon resp) throws rvletexception, ioexception {string action = req.getparameter("action");system.out.println(action);switch(action) {ca "getorderslist":getorderslist(req,resp);break;ca "getorderslistbyname":getorderslistbyname(req,resp);break;ca "deleteorders":deleteorders(req,resp);break;ca "deleteallorders":deleteallorders(req,resp);break;ca "toordersupdatepage":toordersupdatepage(req,resp);break;ca "updateorders":updateorders(req,resp);break;ca "fastbuy":ndorder(req,resp);break;}} /*  * 删除全部订单  */private void deleteallorders(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");// todo 自动生成的方法存根int d = rvice.deleteallorders();try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("删除失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstackt师德师风建设心得体会race();}} /** * 提交订单 * @throws ioexception  */public void ndorder(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss");//设置日期格式ur ur =(ur) req.getssion().getattribute("ur");orders order = new orders();order.tnumber(order.getrandomstring(10));order.ttime(df.format(new date()));order.tname(req.getparameter("recipients"));order.taddress(req.getparameter("address"));order.tphone(req.getparameter("phone"));order.taddress_label(req.getparameter("addresslabel"));order.tx(req.getparameter("x"));order.tur(ur.geturname());order.tgoods_id(integer.parint(req.getparameter("id")));order.tgoods_num(integer.parint(req.getparameter("num")));order.tgoods_status(1);int d = rvice.addorder(order);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult error = jsonresult.errormsg("订单提交失败!");resp.getwriter().println(jsonutil.javaobjecttojson(error));}} catch (exception e) {e.printstacktrace();}} /** * 向前端页面返回订单数据列表 */public void getorderslist(httprvletrequest req,httprvletrespon resp) {list<orders> allorders = rvice.getallorders();req.tattribute("orderslist",allorders);try {req.getrequestdispatcher("/backstage/tgls/ordersmanage/orders_list.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/** * 根据订单名查询商品(注意!类别没改) * @param req * @param resp * @throws ioexception  */public void getorderslistbyname(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");string name = req.getparameter("ordersur");//string type = req.getparameter("type");map<string,string> parmas = new hashmap<>();parmas.put("name", name);//parmas.put("type", type);list<orders> list = rvice.getordersbyname(parmas);try {if(list != null) {jsonresult ok = jsonresult.ok(list);resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("未获取到任何数据,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/** * 修改订单时,获取此订单的全部数据,并返回至修改页面 */public void toordersupdatepage(httprvletrequest req,httprvletrespon resp) {int id = integer.parint(req.getparameter("id"));orders orders = rvice.getordersinfobyid(id);req.tattribute("orders", orders);try {req.getrequestdispatcher("/backstage/tgls/ordersmanage/orders_update.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/** *  修改订单 * @throws ioexception  */public void updateorders(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("ut元日这首诗f-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");orders orders = new orders();orders.tid(integer.parint(req.getparameter("id")));orders.tnumber(req.getparameter("number"));orders.tur(req.getparameter("ur"));orders.ttime(req.getparameter("time"));orders.tname(req.getparameter("name"));orders.tx(req.getparameter("x"));orders.taddress(req.getparameter("address"));orders.tphone(req.getparameter("phone"));orders.taddress_label(req.getparameter("address_label"));orders.tgoods_id(integer.parint(req.getparameter("goods_id")));orders.tgoods_num(integer.parint(req.getparameter("goods_num")));orders.tgoods_status(integer.parint(req.getparameter("goods_status")));system.out.println(orders);int d = rvice.updateordersbyid(orders);system.out.println(d);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}} /** * 删除订单 * @throws unsupportedencodingexception  */public void deleteorders(httprvletrequest req,httprvletrespon resp) throws unsupportedencodingexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");int id = integer.parint(req.getparameter("id"));int d = rvice.deleteordersbyid(id);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("删除失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}}

到此这篇关于java实现茶叶售卖商城系统(java+ssm+jsp+easyui+mysql)的文章就介绍到这了,更多相关java 茶叶售卖商城系统内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!

本文发布于:2023-04-04 02:12:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/a92adbba8aa7cf925dddfd6598b51373.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Java实现茶叶售卖商城系统(java+SSM+JSP+EasyUi+mysql).doc

本文 PDF 下载地址:Java实现茶叶售卖商城系统(java+SSM+JSP+EasyUi+mysql).pdf

标签:格式   订单   商品   密码
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图