• 基于JSP+SSM的网上商城购物网站设计


    资源下载地址:https://download.csdn.net/download/sheziqiong/85838111
    资源下载地址:https://download.csdn.net/download/sheziqiong/85838111

    3 系统设计

    本系统采用B/S模式,前端和后台均使用框架进行开发,前端使用jsp、js和jq技术,后台使用springmvc、spring、mybatis框架整合开发。实现一个完整的网上商城从用户、商品、订单等的管理与操作。以下为详细的设计介绍:

    3.1类结构设计

    在这里插入图片描述

    ​ 图1 类图

    3.2购物基本流程时序图

    在这里插入图片描述

    ​ 图2 购物流程时序图

    3.3数据库设计

    User表,uid为主键。

    在这里插入图片描述

    ​ 图3 买家用户实体E-R图:

    Product表,pid为主键,cid为外键。cid属于category表的主键。

    在这里插入图片描述

    ​ 图4 商品实体E-R图

    Order表,oid为主键,aid为外键,aid是address表的主键。

    在这里插入图片描述

    ​ 图5 订单实体E-R图

    Orderitem表,itemid为主键,oid、pid为外键,oid是order表主键,pid是product表主键。

    在这里插入图片描述

    ​ 图6 order item实体E-R图

    Address表,aid为主键,uid为外键,uid为user表的主键。

    在这里插入图片描述

    ​ 图7 买家地址实体E-R图

    四 系统实现

    4.1 功能模块实现说明

    (1)商品管理:

    4.1.1 商品管理

    后台可以通过该功能模块实现商品上架、商品下架、修改商品信息、查看商品。通过该模块将指定的商品信息增加到数据库中,实现商品上架功能。通过该模块将商城已有商品的商品数目改为0,实现下架商品功能。通过该模块在数据库内修改指定的商品信息,实现修改商品信息功能。

    用户通过该模块实现在前台页面查看和搜索商品,并浏览商品。

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    相关代码:

    //商品分类
    	@RequestMapping("/admin/orderBy")
    	public String orderBy(String cid,String price,String amount,HttpServletRequest request) {
    		List<Product> productList = null;
    		System.out.println("cid:"+cid+"  price:"+price+ "  amount:"+amount);
    		if(cid != null) {
    			productList = service.getProductByDetails(cid,price,amount);
    		}
    		request.setAttribute("productList", productList);
    		
    		return "admin/newProductManage";
    	}
    	
    	//弹窗展示获得的商品数据
    	@RequestMapping("/admin/showProductInfo")
    	public void showProduct(String pid,HttpServletRequest request,HttpServletResponse response) throws IOException {
    		Product product = productservice.getProductInfo(pid);
    		Gson gson = new Gson();
    		String json = gson.toJson(product);
    		response.getWriter().write(json);
    	}
    	@RequestMapping("/admin/modifyProduct")
    	public void modifyProduct(Product product,HttpServletResponse response) throws IOException {
    		System.out.println(product.getPid());
    		productservice.modifyProduct(product);
    		response.getWriter().write("{\"isSuc\":"+true+"}");
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    4.1.2 分类管理

    后台可以通过该功能模块实现增加商品分类,修改商品分类以及删除商品分类等功能要求。对应在数据库中对分类信息进行增删改。

    用户通过该功能模块实现商品的分类浏览。
    在这里插入图片描述
    在这里插入图片描述

    相关代码:

    AdminController:
    @RequestMapping("/admin/orderManage")
    	public String orderManage(HttpServletRequest request) {
    		List<Order> orderList = orderservice.getAllOrder();
    
    		Gson gson = new Gson();
    		String json = gson.toJson(orderList);
    		request.setAttribute("orderList", orderList);
    		request.setAttribute("json", json);
    		return "admin/orderManage";
    	}
    productController:
    @RequestMapping("/productByCategory")
    	public String getOrderByUser(String cid, @RequestParam(value = "currentPage", defaultValue = "1") int currentPage,
    			HttpServletRequest request) {
    		PageBean pagebean = service.getProductListByCid(cid, currentPage);
    		request.setAttribute("pageBean", pagebean);
    		request.setAttribute("cid", cid);
    		return "productList";
    	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    4.1.3 订单管理

    用户通过该模块查看自己的订单信息、提交订单、删除订单以及更改订单收货状态。

    后台通过该模块查看所有用户的订单信息以及更改订单的发货状态。

    4.1.4 用户权限

    用户权限分为一般浏览者和买家。一般浏览者可以查看所有商品信息,但是不能购买商品以及没有个人中心,在选择购买时会跳到用户注册登录界面。买家则是已登录的用户,可以购买商品也拥有自己的个人中心,可查看自己的个人信息。

    在这里插入图片描述
    在这里插入图片描述

    相关代码:

    UserInterceptor.java 登录拦截器:
    public class UserInterceptor implements HandlerInterceptor {
    	
    	@Override
    	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
    		HttpSession session = request.getSession();
    		Object user = session.getAttribute("user");
    		if(user != null) {
    			return true;
    		}else {
    			response.sendRedirect(request.getContextPath()+"/login.html");
    		}
    		return false;
    	}
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    4.1.5 注册与登录

    用户只有在登录后才可以购买商品以及查看个人信息,没有账户的游客则需要进行注册再登录。

    在这里插入图片描述

    图25 注册新账号

    相关代码:

    UserConroller@RequestMapping("/login")
    	public void login(String account, String password, HttpServletRequest request, HttpServletResponse response)
    			throws Exception {
    		String email = "";
    		String username = "";
    		boolean flag = false;
    		try {
    			String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    			Pattern regex = Pattern.compile(check);
    			Matcher matcher = regex.matcher(account);
    			flag = matcher.matches();
    		} catch (Exception e) {
    			flag = false;
    		}
    		if (flag) {
    			email = account;
    		} else {
    			username = account;
    		}
    
    		System.out.println("email:" + email);
    		System.out.println("username:" + username);
    		User user = new User();
    		user.setUsername(username);
    		user.setEmail(email);
    		user.setPassword(password);
    
    		User logined = service.login(user);
    
    		boolean isSuccess = true;
    		System.out.println(logined);
    		HttpSession session = request.getSession();
    		if (logined != null) {
    			session.setAttribute("user", logined);
    			response.getWriter().write("{\"isSuccess\":" + isSuccess + "}");
    		}else {
    			isSuccess = false;
    			response.getWriter().write("{\"isSuccess\":" + isSuccess + "}");
    		}
    
    	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    4.1.6 浏览商品

    所有人都可以浏览商品。

    在这里插入图片描述
    在这里插入图片描述

    相关代码:

    ProductController//根据pid展示商品
    	@RequestMapping("/product")
    	public String productInfo(String pid, HttpServletRequest request) {
    
    		Product product = service.getProductInfo(pid);
    		request.setAttribute("product", product);
    
    		return "productInfo";
    	}
    
    indexController:
    //展示最新和热门商品
    @RequestMapping(value = {"/","/index"})
    	public String index(Model model) {
    		
    		List<Product> hotProductList = indexservice.getHotProducts();
    		List<Product> newProductList = indexservice.getNewProducts();
    		model.addAttribute("hotProductList", hotProductList);
    		model.addAttribute("newProductList", newProductList);
    		
    		return "index";
    	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    4.1.7 用户信息管理

    用户可以在这里查看自己的所有信息,以及地址管理和充值服务。

    在这里插入图片描述
    在这里插入图片描述

    相关代码:

    userController:
    @RequestMapping("/user/userInfo")
    	public String toUserInfo() {
    		return "privilege/userInfo";
    	}
    	// 修改用户信息
    	@RequestMapping("/user/modify")
    	public void modifyUserInfo(User user, HttpServletRequest request, HttpServletResponse response) throws Exception {
    		System.out.println(user);
    
    		service.modifyUserInfo(user);
    		User newUser = service.getUser(user.getUid());
    		HttpSession session = request.getSession();
    		Boolean isSuccess = false;
    		if (newUser != null) {
    			isSuccess = true;
    			session.setAttribute("user", newUser);
    		}
    		response.getWriter().write("{\"isSuccess\":" + isSuccess + "}");
    	}
    
    	// 前往充值余额页面
    	@RequestMapping("/user/balance")
    	public String toBalancePage() {
    		return "privilege/balance";
    	}
    	// 充值余额
    	@RequestMapping("/user/recharge")
    	public void recharge(Double pay, HttpServletRequest request, HttpServletResponse response) throws Exception {
    		HttpSession session = request.getSession();
    		User user = (User) session.getAttribute("user");
    		Double money = user.getMoney();
    		Double newMonney = 0.0;
    		if (pay != 0.0 && pay != null) {
    			newMonney = money + pay;
    		}
    		System.out.println("money:" + newMonney);
    		user.setMoney(newMonney);
    
    		service.modifyUserInfo(user);
    		user = service.getUser(user.getUid());
    		System.out.println(user);
    		session.setAttribute("user", user);
    		Boolean isSuccess = false;
    		if (user.getUid() != "") {
    			isSuccess = true;
    		}
    		response.getWriter().write("{\"isSuccess\":" + isSuccess + "}");
    }
    	// 跳转到支付成功页面
    	@RequestMapping("/user/paySuccess")
    	public String topaySuccessPage() {
    		return "privilege/recharge";
    	}
    
    	// getAddsByUser
    	@RequestMapping("/user/address")
    	public String addressManage(HttpServletRequest request) {
    		HttpSession session = request.getSession();
    		User user = (User) session.getAttribute("user");
    		List<Address> addList = service.getAddress(user.getUid());
    		request.setAttribute("addList", addList);
    		
    		return "privilege/addManage";
    	}
    	
    	// 添加或修改用户地址
    	@RequestMapping("/user/addManage")
    	public String addManage(String aid,String tel,String address,String name,HttpServletRequest request) {
    		System.out.println(aid);
    		System.out.println(tel);
    		System.out.println(address);
    		System.out.println(name);
    		
    		Address address1 = new Address();
    		address1.setAid(aid);
    		address1.setTel(tel);
    		address1.setAddress(address);
    		address1.setName(name);
    		
    		System.out.println(address1);
    		HttpSession session = request.getSession();
    		User user = (User)session.getAttribute("user");
    		address1.setUid(user.getUid());
    		System.out.println(address1);
    		if(address1.getAid() != null && address1.getAid() != "") {
    			service.updateAdd(address1);
    		}else {
    			service.addAddress(address1);
    		}
    		
    		return "redirect:/user/address";
    	}
    	
    	//删除地址
    	@RequestMapping("/user/delAdd")
    	public String delAdd(@RequestParam(value = "aid") String aid) {
    		Address address = new Address();
    		address.setAid(aid);
    		
    		service.delAdd(address);
    		
    		return "redirect:/user/address";
    	}
    	
    	//设置默认地址
    	@RequestMapping("/user/setDefaultAdd")
    	public String setDefaultAdd(String aid,HttpServletRequest request) {
    		HttpSession session = request.getSession();
    		User user = (User)session.getAttribute("user");
    		
    		Address address = new Address();
    		address.setAid(aid);
    		address.setUid(user.getUid());
    		
    		service.setDefaultAdd(address);
    		
    		
    		return  "redirect:/user/address";
    	}
    	
    	@RequestMapping("/user/setDefaultAddFromCart")
    	public String setDefaultAddFromCart(String aid,HttpServletRequest request) {
    		HttpSession session = request.getSession();
    		User user = (User) session.getAttribute("user");
    		Address address = new Address();
    		address.setAid(aid);
    		address.setUid(user.getUid());
    		
    		service.setDefaultAdd(address);
    		
    		List<Address> addList = service.getAddress(user.getUid());
    		
    		session.setAttribute("addListCart", addList);
    		
    		return "redirect:/cart.html";
    		
    	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139

    4.18 购物车模块

    用户可以将自己心仪的商品先添加至购物车,然后继续浏览其他商品,最后再进行付款提交订单。

    在这里插入图片描述
    在这里插入图片描述

    图35 购物车为空

    相关代码:

    Productcontroller:
    // 加入购物车
    	@RequestMapping("/addCart")
    	public String addCart(String pid, int buyNum, HttpServletRequest request) {
    		HttpSession session = request.getSession();
    
    		Cart cart = (Cart) session.getAttribute("cart");
    		if (cart == null) {
    			cart = new Cart();
    		}
    		CartItem cartitem = new CartItem();
    		Product product = service.getProductInfo(pid);
    		cartitem.setProduct(product);
    		cartitem.setBuyNum(buyNum);
    
    		double subtotal = product.getPrice() * buyNum;
    		cartitem.setSubtotal(subtotal);
    		
    		double total = 0.0d;
    		Map<String, CartItem> cartItems = cart.getCartItems();
    		if(cartItems.containsKey(pid)) {
    			CartItem item = cartItems.get(pid); 
    			int oldNum = item.getBuyNum();
    			int newNum = oldNum+buyNum;
    			item.setBuyNum(newNum);
    			item.setSubtotal(product.getPrice()*newNum);
    			cart.setCartItems(cartItems);
    		}else {
    			cartItems.put(pid, cartitem);
    		}
    		
    		total = cart.getTotal()+cartitem.getSubtotal();
    		cart.setTotal(total);
    		User user = (User) session.getAttribute("user");
    		if (user != null) {
    			List<Address> address = userservice.getAddress(user.getUid());
    			System.out.println(address);
    			session.setAttribute("addListCart", address);
    		}
    		session.setAttribute("cart", cart);
    		return "redirect:/cart.html";
    	}
    	
    	@RequestMapping("/delCartItem")
    	public String delCartItem(String pid,HttpServletRequest request) {
    		HttpSession session = request.getSession();
    		Cart cart = (Cart) session.getAttribute("cart");
    		if(cart!=null) {
    			Map<String, CartItem> cartItems = cart.getCartItems();
    			//修改总价
    			double  newTotal = cart.getTotal() - cartItems.get(pid).getSubtotal();
    			cart.setTotal(newTotal);
    			// 删除
    			cartItems.remove(pid);
    			cart.setCartItems(cartItems);
    		}
    		session.setAttribute("cart", cart);
    		return "redirect:/cart.html";
    	}
    	@RequestMapping("/removeCart")
    	public String removeCart(HttpServletRequest request) {
    		HttpSession session = request.getSession();
    		session.removeAttribute("cart");
    		
    		return "redirect:/cart.html";
    		
    	}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68

    4.2 配置文件

    ApplicationContext.xml是web应用中spring框架的配置文件,负责对web系统中beanfactory和各个bean的属性注入以及数据库连接池的配置设置。

    部分配置代码如下:

    <context:property-placeholder
    		location="classpath:db.properties" />
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="driverClassName" value="${jdbc.driver}" />
    		<property name="url" value="${jdbc.url}" />
    		<property name="username" value="${jdbc.username}" />
    		<property name="password" value="${jdbc.password}" />
    		<property name="maxActive" value="10" />
    		<property name="maxIdle" value="5" />
    	</bean>
    
    	<!-- sqlSessionFactory -->
    	<bean id="sqlSessionFactory"
    		class="org.mybatis.spring.SqlSessionFactoryBean">
    		<!-- mybatis核心配置 -->
    		<property name="configLocation"
    			value="classpath:SqlMapConfig.xml"></property>
    		<!-- 数据源 -->
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    	<!-- mapper扫描器 -->
    	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    		<property name="basePackage" value="cn.fpshop.dao" />
    	</bean>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    Springmvc.xml是基于SSM的web系统中SpringMVC的配置文件。负责对springmvc的核心组件前端控制器、处理器等进行配置

    =“${jdbc.password}” />


    <!-- sqlSessionFactory -->
    <bean id="sqlSessionFactory"
    	class="org.mybatis.spring.SqlSessionFactoryBean">
    	<!-- mybatis核心配置 -->
    	<property name="configLocation"
    		value="classpath:SqlMapConfig.xml"></property>
    	<!-- 数据源 -->
    	<property name="dataSource" ref="dataSource" />
    </bean>
    <!-- mapper扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    	<property name="basePackage" value="cn.fpshop.dao" />
    </bean>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    
    
    • 1

    Springmvc.xml是基于SSM的web系统中SpringMVC的配置文件。负责对springmvc的核心组件前端控制器、处理器等进行配置
    资源下载地址:https://download.csdn.net/download/sheziqiong/85838111
    资源下载地址:https://download.csdn.net/download/sheziqiong/85838111

  • 相关阅读:
    android webview加载第三方网页,<select>控件无法弹出的问题
    Vue项目实战——【基于 Vue3.x + NodeJS】实现的课程表排课系统三(duration-title)
    特征匹配算法GMS(Grid-based Motion Statistics)理论与实践
    带你揭开神秘的javascript AST面纱之AST 基础与功能
    if 语句 python
    C++初阶:C++入门
    外贸SEO 站长工具
    集合-Map系列
    基于分步表单的实践探索
    深入解析HTTP(web开发详细理解原理)【JavaWeb】
  • 原文地址:https://blog.csdn.net/sheziqiong/article/details/125544527