提示:此项目仅供学习使用,不作为商品售卖,仅作为本博主的学习笔记记录,资源可找博主私聊
文章目录
前言
提示:这里可以添加本文要记录的大概内容:
本项目要求完成Java Web的开发环境准备,以及项目开发框架的搭建
Web开发环境准备,包括eclipse、MySQL、tomcat
Web项目框架搭建,涉及jsp、servlet、MVC等技术
运行网址:http://localhost:8080/eshop0/index.action
提示:以下是本篇文章正文内容,下面案例可供参考
Web端功能设计
首页
热销商品
新到商品
商品分类
商品详情
![在这里
购物车
添加地址
提交订单
部分代码展示
GoodsController中的搜索商品功能
//搜索商品elseif(url.equals("/goods/searchGoods.action")){String keyword=req.getParameter("keyword");String sort=req.getParameter("sort");List<Goods> searchGoods=newArrayList<Goods>();if(keyword!=null&&!keyword.equals("")){
searchGoods=GoodsService.searchGoodsByKeywords(keyword,sort);
req.setAttribute("goods", searchGoods);}
req.getRequestDispatcher("/goods/goods_list.jsp").forward(req, resp);}elseif(url.equals("/goods/deleteCart.action")){
resp.setContentType("text/json; charset=utf-8");PrintWriter out = resp.getWriter();String index=req.getParameter("index");List<Goods> goodslist=newArrayList<Goods>();Object ob=req.getSession().getAttribute("goodslist");if(ob!=null&&index!=null){
goodslist=(List<Goods>) ob;
goodslist.remove(Integer.parseInt(index));}
req.getSession().setAttribute("goodslist", goodslist);
out.print("{\"success\":true,\"cartnum\":"+goodslist.size()+"}");}elseif(url.equals("/goods/clearCart.action")){
resp.setContentType("text/json; charset=utf-8");PrintWriter out = resp.getWriter();
req.getSession().removeAttribute("goodslist");
out.print("{\"success\":true}");}elseif(url.equals("/goods/changeCart.action")){List<Goods> goodslist=newArrayList<Goods>();Object ob=req.getSession().getAttribute("goodslist");if(ob!=null){
goodslist=(List<Goods>) ob;}
resp.setContentType("text/json; charset=utf-8");PrintWriter out = resp.getWriter();String index=req.getParameter("index");String goodsSales=req.getParameter("goodsSales");float totalAmount=0;float totalPrice=0;if(ob!=null){for(int i=0;i<goodslist.size();i++){if(i==Integer.parseInt(index)){
goodslist.get(i).setGoodsSales(Integer.parseInt(goodsSales));
totalPrice=goodslist.get(i).getGoodsSales()*goodslist.get(i).getGoodsDiscount();}
totalAmount=totalAmount+goodslist.get(i).getGoodsSales()*goodslist.get(i).getGoodsDiscount();}}
out.print("{\"success\":true,\"totalAmount\":"+totalAmount+",\"totalPrice\":"+totalPrice+"}");}elseif(url.equals("/goods/buyGoods.action")){
req.setAttribute("catelist", catelist);User logu=(User)req.getSession().getAttribute("_LOGIN_USER_");if(logu!=null){// List<Address> addresses=AddressService.getAllAddress(logu.getUserId()); //req.setAttribute("addrs",addresses); }
req.getRequestDispatcher("/order/buyGoods.jsp").forward(req, resp);}
GoodsService中的搜索商品功能
//byzmhpublicstaticList<Goods>searchGoodsByKeywords(String name,String sort){// TODO Auto-generated method stubDBUtil1 db=newDBUtil1();// 连接数据库String sql="select * from t_goods where goods_name like ? ";if(sort!=null)if(sort.equals("1"))
sql=sql+" order by goods_discount asc";elseif(sort.equals("2"))
sql=sql+" order by goods_discount desc";elseif(sort.equals("3"))
sql=sql+" order by goods_sales desc";elseif(sort.equals("4"))
sql=sql+" order by goods_sales asc";String params[]={"%"+name+"%"};List<Map<String,String>> goods_map=db.getList(sql,params);if(goods_map!=null)returnmaptomodel(goods_map);elsereturnnull;}
可能会出现的错误
如果拿到项目后发现图片不显示
1、找到项目中的代码,看一下是不是图片地址不对,对应地址【/images】下查看
2、检查是不是数据库连接问题
数据库连接工具 DBUtil.java
源码获取
点击此处转到源码地址:
基于Java Web的随意购商城系统
链接:https://pan.baidu.com/s/1x6rh_ethX3kcIobm8MzJ4w
提取码:fpg5
版权归原作者 二哈喇子! 所有, 如有侵权,请联系我们删除。