JAVA&Web项目之购物系统(饱了么)

 

开发工具:Eclipse

数据库:Oracle

应用服务:Tomcat8.0

登录界面 

当用户登录时,先判断当前登录用户购物车是否有数据。判断当前用户是否为第一次登路,保存登录时间。

@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String name = req.getParameter("adminname");
		String pwd = req.getParameter("adminpwd");
		IUserBiz ub = new UserBiz();

		PrintWriter out = resp.getWriter();
		// 登录
		Part p1 = ub.login(name, pwd);
		if (p1 != null) {
			// 保存用户信息
			req.getSession().setAttribute("p", p1);
			// 获取cookie
			Cookie[] cookies = req.getCookies();
			boolean flag = false;
			if (cookies != null && cookies.length > 0) {
				for (Cookie coo : cookies) {
					// 当cookie的name与用户name相同时
					if (String.valueOf(p1.getPartid()).equals(coo.getName())) {
						flag = true;
						// 购物车信息
						String value = coo.getValue();
						// 转换成list
						List<ShopCar> list1 = JSON.parseArray(URLDecoder.decode(value, "utf-8").toString(),
								ShopCar.class);
						// 保存到Session中
						req.getSession().setAttribute("car", list1);
					}
				}
			}
			if (!flag) {
				List<ShopCar> list = new ArrayList<ShopCar>();// 创建一个购物车
				req.getSession().setAttribute("car", list);
			}
			req.getSession().setMaxInactiveInterval(60 * 60 * 60);
			List<GoodsType> type = ub.getgoodstype();// 种类
			req.getSession().setAttribute("type", type);
			out.print("登录成功");
			Cookie[] cookiess = req.getCookies();
			// 从数组中查找指定名称的cookie
			Cookie cookie = null;
			for (Cookie vs : cookiess) {
				if (vs.getName().equals("lastvisit")) {
					cookie = new Cookie(vs.getName(), vs.getValue());
				}
			}
			// 创建一个cookie的对象
			Cookie cook = new Cookie("lastvisit", "" + System.currentTimeMillis());// 获取当前时间存入cookie中
			// cook.setMaxAge(60*60*24*19);//设置cookie保存时间
			resp.addCookie(cook);// 保存到浏览器端
			String count = "";
			if (cookie == null) {
				// 第一次访问
				count = "欢迎光临!!!!";
			} else {
				long l = Long.parseLong(cookie.getValue());// 将string转换成long
				Date d = new Date(l);
				count = " 您上次访问时间为" + d.toLocaleString();
			}
			req.getSession().setAttribute("count", count);

		} else {
			out.print("登录失败");
		}

	}
}

 首页 

 在首页中猜你喜欢板块功能分析:

  • 通过用户id查询订单表得到商品id
  •  通过商品ID查询商品表再根据商品类别分组获并计数然后降序
  •  获取第一的商品类别,再根据类别查询商品表,获取前五个商品

 商品浏览

 

 

购物车 

 当用户点击结算时,会判断当前用户是否有收获地址,没有则自动跳转到添加地址页面,有则跳转到地址选择界面

用户收藏

同样个人收藏也会保存,当用户收藏相同商品时,提示你已收藏过该商品

 最近浏览

保存个人数据 

@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Part p = (Part) req.getSession().getAttribute("p");
		IUserBiz biz = new UserBiz();
		//获得当前用户浏览的所有商品
		List<look> look = biz.getlook(p.getPartid());
		//list用来装时间 以一天为个单位
		List<String> list = new ArrayList<String>();
		if (look != null && look.size() > 0) {
			for (look k : look) {
				if (!list.contains(k.getGoodstime())) {
					list.add(k.getGoodstime());
				}
			}
		}
		//map集合存放数据
		Map<String, Object> m = new HashMap<String, Object>();
		for (String sqltime : list) {
			List<look> getlooktime = biz.getlooktime(sqltime);
			m.put(sqltime, getlooktime);
		}

		req.setAttribute("look", m);
		req.setAttribute("time", list);

		req.getRequestDispatcher("look.jsp").forward(req, resp);
	}

 我的订单

以鼓风琴的样式做展示;头部为订单,里面为当前订单的订单项

 项目总体没有什么难点,存在即合理,合理即可实现。逻辑最为重要!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值