Software engineering completed the establishment of an online mobile phone sales system based on java web [source code + paper]


foreword

Today, seniors share with you a java web graduation design project:

Online mobile phone sales system based on java web

Project acquisition:
https://gitee.com/sinonfin/L-javaWebSha

1. Project design

1. Modular design

business flow design

insert image description here

Front-end module design

(1) Commodity booth module: Through the new products on the shelves, display special products in pages, and display all the products on the website
according to the product sales ranking; (2) Product query module: query the relevant information of products according to the category of products;
(3) Shopping cart module: users Add items to the shopping cart, check the items in the shopping cart, remove unsatisfactory items from the shopping cart, clear the products in the shopping cart, and modify the quantity of items to be purchased; (4) Cash register module: the user is satisfied with the shopping
cart (5) User maintenance
module: provides users with the functions of user registration, user login, user profile modification and password retrieval; (6
) Order query module: users can check the order Know your own current order information and historical order records;
(7) Announcement browsing module: Users can learn about the latest information of the website in a timely manner by browsing the announcement information.
(8) Message module: Customers can leave messages to give us their opinions, and we are advancing in continuous improvement.

Background system function module

(1) Product management module: View products by category and maintain product information;
(2) User management module: In order to protect user information, the difference between this module and front-end user maintenance is that administrators can only view user information and delete Operation;
(3) Administrator maintenance module: This is to maintain the administrator's information, and the administrator's information can be modified.
(4) Order management module: administrators can query orders, view order details, delete order information, and accept orders; (5)
Announcement management module: administrators can browse announcements and maintain announcement information;
(6) Message module: administrators can Check the customer's message and maintain the message.

insert image description here

2. Realize the effect

insert image description here
insert image description here
insert image description here
insert image description here

insert image description here

insert image description here
insert image description here

2. Part of the source code

There are many source codes and the length of the article is limited, so I won’t post them here, and only show a small part of the key code

Some code examples:

购物车核心代码
在userAction中:
public String userLogin()
	{
    
    
		String sql="from TUser where userName=? and userPw=?";
		Object[] con={
    
    userName,userPw};
		List userList=userDAO.getHibernateTemplate().find(sql,con);
		if(userList.size()==0)
		{
    
    
			this.setMessage("用户名或密码错误");
			this.setPath("qiantai/index.html");
		}
		else
		{
    
    
			 Map session= ServletActionContext.getContext().getSession();
			 TUser user=(TUser)userList.get(0);
			 session.put("user", user);
			 Cart cart=new Cart();          //用户登陆成功后生成购物车,并将其放入到session中。
			 session.put("cart", cart);
			 this.setMessage("成功登录");
			 this.setPath("qiantai/index.html");
		}
		return "succeed";
	}

在buyAction中:
	public String addToCart()
	{
    
    
		TGoods goods=goodsDAO.findById(goodsId);
		TOrderItem orderItem=new TOrderItem();
		orderItem.setGoods(goods);
		orderItem.setGoodsQuantity(quantity);
		Map session= ServletActionContext.getContext().getSession();
		Cart cart = (Cart)session.get("cart");     //将session中的cart取出,也就是上边存储在session中的cart
		cart.addGoods(goodsId, orderItem);
		session.put("cart",cart);              //再把cart放入session
		//this.setMessage("");
		this.setPath("myCart.action");
		return "succeed";
	}
	public String myCart()				 //获取我的购物车
	{
    
    
		return ActionSupport.SUCCESS;
	}
	public String orderQueren()                 //确认提交订单
	{
    
    
		Map request=(Map)ServletActionContext.getContext().get("request");
		return ActionSupport.SUCCESS;
	}
	public String orderSubmit()		//订单提交
	{
    
    
		Map session= ServletActionContext.getContext().getSession();
		Cart cart = (Cart)session.get("cart");                //将cart取出
		TUser user=(TUser)session.get("user");		       //将用户取出
		TOrder order=new TOrder();
		order.setOrderBianhao(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));        //设定订单编号
		order.setOrderDate(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));      //确认订单的日期
		order.setOrderZhuangtai("no");                       //订单状态默认为未受理                                      
		order.setOrderUserId(user.getUserId());                 //设定订单的用户ID
        order.setOrderJine(cart.getTotalPrice());			    //商品的价格
		orderDAO.save(order);					            //保存订单
			
		for (Iterator it = cart.getItems().values().iterator(); it.hasNext();)
     //把订单里的商品存入数据库
		{
    
    
			TOrderItem orderItem = (TOrderItem) it.next();
			orderItem.setOrderId(order.getOrderId());
			orderItem.setGoodsId(orderItem.getGoods().getGoodsId());
			orderItemDAO.save(orderItem);
		}
		cart.getItems().clear();								 //清空购物车
		session.put("cart", cart);
		
		Map request=(Map)ServletActionContext.getContext().get("request");
		request.put("order", order);
		return ActionSupport.SUCCESS;
			}
			Public	String	myOrder()       	        //根据用户查询订单
	{
    
    
		Map session= ServletActionContext.getContext().getSession();
		TUser user=(TUser)session.get("user");			 //获取用户
		String sql="from TOrder where orderUserId="+user.getUserId();
		List orderList=orderDAO.getHibernateTemplate().find(sql);			 //调用orderDAO中的find方法,执行sql语句
		Map request=(Map)ServletActionContext.getContext().get("request");		
		request.put("orderList", orderList);					
		return ActionSupport.SUCCESS;
	}
		public String orderMana()				 //订单管理
	{
    
    
		String sql="from TOrder order by orderUserId";
		List orderList=orderDAO.getHibernateTemplate().find(sql);
		Map request=(Map)ServletActionContext.getContext().get("request");
		request.put("orderList", orderList);
		return ActionSupport.SUCCESS;
	}
			Public	String	 orderDel()                                                            //用户自己删除订单
	{
    
    
		TOrder order=orderDAO.findById(orderId);
		orderDAO.delete(order);
			
		Map session= ServletActionContext.getContext().getSession();
		TUser user=(TUser)session.get("user");
		
		this.setMessage("删除成功");
		this.setPath("myOrder.action?userId="+user.getUserId());     //跳转到 myOrder.action
		return "succeed";
	}
		public String orderDelByAd()                                                       //管理员删除订单
	{
    
    
		TOrder order=orderDAO.findById(orderId);
		orderDAO.delete(order);
		String sql="delete from TOrderItem where orderId="+orderId;
		orderItemDAO.getHibernateTemplate().bulkUpdate(sql);
		
		this.setMessage("删除成功");
		this.setPath("orderMana.action");
		return "succeed";
	}
		public String orderShouli()							 //对订单进行受理
	{
    
    
		TOrder order=orderDAO.findById(orderId);
		order.setOrderZhuangtai("yes");//已经受理订单
		orderDAO.attachDirty(order);
		this.setMessage("受理订单成功");
		this.setPath("orderMana.action");
		return "succeed";
	}
				public String orderDetail()                 //订单明细
	{
    
    
		String sql="from TOrderItem where orderId="+orderId;
		List orderItemList=orderItemDAO.getHibernateTemplate().find(sql);
		for(int i=0;i<orderItemList.size();i++)
		{
    
    
			TOrderItem orderItem=(TOrderItem)orderItemList.get(i);
			orderItem.setGoods(goodsDAO.findById(orderItem.getGoodsId()));
		}       //取出订单里的商品
		Map request=(Map)ServletActionContext.getContext().get("request");
		request.put("orderItemList", orderItemList);
		return ActionSupport.SUCCESS;
	}
	在cart.java中
package com.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.model.TGoods;
import com.model.TOrderItem;
public class Cart            //定义购物车类
{
    
    
	protected Map<Integer, TOrderItem> items;
	public Cart()                                                  //定义构造方法
	{
    
    
		if (items == null)
		{
    
    
			items = new HashMap<Integer, TOrderItem>();
		}
	}
	public void addGoods(Integer goodsId, TOrderItem orderItem)		 //添加购物车
	{
    
    

		if (items.containsKey(goodsId))                                   
		{
    
    
			TOrderItem _orderitem = items.get(goodsId);
			_orderitem.setGoodsQuantity(_orderitem.getGoodsQuantity()+ orderItem.getGoodsQuantity());             //如果购买商品重复,则加上数量
			items.put(goodsId, _orderitem);
		} else
		{
    
    
			items.put(goodsId, orderItem);
		}
	}
		Public	void	delGoods(Integer	goodsId)                                  //删除购物车
	{
    
    
		items.remove(goodsId);
	}
		public void updateCart(Integer goodsId, int quantity)			 //更新购物车的数量
	{
    
    
		TOrderItem orderItem = items.get(goodsId);
		orderItem.setGoodsQuantity(quantity);
		items.put(goodsId, orderItem);
	}
public int getTotalPrice()	//计算总的价格
	{
    
    
		int totalPrice = 0;
		for (Iterator it = items.values().iterator(); it.hasNext();)
		{
    
    
			TOrderItem orderItem = (TOrderItem) it.next();
			TGoods goods = orderItem.getGoods();
			int quantity = orderItem.getGoodsQuantity();
			totalPrice += goods.getGoodsTejia() * quantity;          //单价乘以数量
		}
		return totalPrice;
	}
}

Project source code

Project acquisition:
https://gitee.com/sinonfin/L-javaWebSha

Guess you like

Origin blog.csdn.net/mojikopi/article/details/132036762