随着科技创新不断突破玩具界限,特别是随着智能时代到来,电子游戏的兴起对传统玩具行业带来了冲击,智能玩具应运而生,成为新产品方向。智能玩具受消费者青睐,
随着电子商务的发展,其在我国的经济地位越来越重要[3],一大批电子商务 应用逐渐被开发出来,例如,阿里巴巴旗下的淘宝,天猫,亚马逊,京东等,这 些都已成为流行的电子商务系统。互联网已经逐渐引发新的产业革命,在当今经 济领域中依靠互联网的电子商务已经越来越重要。本文主要在了解这些背景的情 况下,设计出一款电子商务系统用于在线交易玩具商品,给企业以及消费者提供一个 可信赖的购物平台。
本商城网站采用B/S结构,web开发,用户自己在浏览器中输入网址来浏览网页中的信息。 采用mysql数据库来存储所有动态数据,本网站从技术方向来说,分为前端页面和后台逻辑开发,页面设计使用html+js+jquery技术,后台使用springboot+JPA。将IDEA作为编译环境,Java作为本网站的开发语言来设计开发。网上玩具商城系统开发环境如表1-1所示。
项目演示视频:
基于springboot玩具商城平台java web玩具玩偶商城毕业设计源码含支付宝沙箱
表1-1 系统开发环境表
操作平台: | Windows 10 |
硬件平台: | CPU:i7 |
内存: 8G | |
硬件平台: | 硬盘:500GB |
数据库: | MySql |
开发工具: | IDEA |
开发浏览器: | Google,火狐 |
网站站的设计与实现采用IDEA+jdk1.8作为开发环境,页面设计使用html技术和前端框架bootstrap,后台采用springboot+JPA+MySql来实现。开发过程应用了MVC模式。
开发环境
本网站以IDEA作为集成开发环境,后台服务器采用springboot内置的tomcat,软件开发工具包选用JDK1.8。
JDK作为java开发必备的环境,IDEA才能正常工作。IDEA是一个优秀成熟的java开发工具,已经用了几十年了,不管是学生还是公司的开发人员的不二之选,
页面设计
本系统采用html作为前端显示。html学习简单易懂,大部分学生和老师都在用,html在配合前端框架bootstrap或者其他前端框架的时候开发非常简易,而且快速,是作为开发前端显示的良好选择。
后台设计
后台采用springboot+JPA作为后台框架。springboot的目的是为了简化Spring应用的搭建以及开发过程,它默认配置了很多框架的使用方式,就像maven整合了所有的jar包,springboot整合了所有的框架。
本系统采用支付宝沙箱支付,关键代码如下:
package com.scut.mall.controller.user;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.google.gson.Gson;
import com.scut.mall.entity.Order;
import com.scut.mall.entity.OrderItem;
import com.scut.mall.entity.User;
import com.scut.mall.entity.pojo.ResultBean;
import com.scut.mall.service.OrderService;
import com.scut.mall.utils.AlipayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
/**
* @ Author :java
* @ Date :2022/4/22 23:47
* @ Description:订单控制层类
* @ Modified By:
*/
@Controller
@RequestMapping("/order")
public class OrderController {
@Autowired
private OrderService orderService;
/**
* 打开订单列表页面
*
* @return
*/
@RequestMapping("/toList.html")
public String toOrderList() {
return "mall/order/list";
}
/**
* 查询用户订单列表
*
* @param pageindex,request
* @return
*/
@RequestMapping("/list.do")
@ResponseBody
public ResultBean<List<Order>> listData(int pageindex , HttpServletRequest request,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
Pageable pageable = PageRequest.of(pageindex, pageSize, Sort.by(Sort.Direction.ASC,"id"));
List<Order> orders = orderService.findUserOrder(request, pageable).getContent();
return new ResultBean<>(orders);
}
/**
* 查询订单详情
*
* @param orderId
* @return
*/
@RequestMapping("/getDetail.do")
@ResponseBody
public ResultBean<List<OrderItem>> getDetail(int orderId) {
List<OrderItem> orderItems = orderService.findItems(orderId);
return new ResultBean<>(orderItems);
}
// /**
// * 提交订单
// *
// * @param addressId
// * @param request
// * @param response
// */
// @RequestMapping("/submit.do")
// public void submit(Integer addressId,
// HttpServletRequest request,
// HttpServletResponse response) throws Exception {
// orderService.submit(addressId, request, response);
// }
@ResponseBody
@RequestMapping(method = RequestMethod.POST, value = "/submit.do")
public ResultBean<Boolean> submit(int address, HttpServletRequest request, HttpServletResponse response) throws Exception{
orderService.submit( address, request, response );
return new ResultBean<>(true);
}
/**
* 支付方法
*
* @param orderId
*/
@RequestMapping("pay1.do")
@ResponseBody
public ResultBean<Boolean> pay1(int orderId,HttpServletRequest request, HttpServletResponse response) throws Exception,IOException {
orderService.pay(orderId,request,response);
return new ResultBean<>(true);
}
@RequestMapping("pay.do")
@ResponseBody
public String pay(int orderId,HttpServletRequest request, HttpServletResponse response) throws Exception,IOException {
Order order = orderService.findById(orderId);
User user = (User) request.getSession().getAttribute("user");
request.getSession().setAttribute("orderId", orderId);
String username="";
if(user!=null){
username=user.getUserName();
}
Gson gson = new Gson();
//商户订单号,商户网站订单系统中唯一订单号,必填
String out_trade_no =UUID.randomUUID().toString();
//获得初始化的AlipayClient
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
//设置请求参数
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
//这里设置支付后跳转的地址
alipayRequest.setReturnUrl(AlipayConfig.return_url);
//alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
//付款金额,必填
String total_amount = String.valueOf(order.getTotal());
//订单名称,必填
String subject ="用户"+username+"订单";
//商品描述,可空
String body = "";
// 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
String timeout_express = "5m";
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"total_amount\":\""+ total_amount +"\","
+ "\"subject\":\""+ subject +"\","
+ "\"body\":\""+ body +"\","
+ "\"timeout_express\":\""+ timeout_express +"\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//请求
String result = alipayClient.pageExecute(alipayRequest).getBody();
return result;
}
@RequestMapping("payreturn")
public String alipayNotifyNotice( HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("支付成功。。。。");
int orderId = (int) request.getSession().getAttribute("orderId");
orderService.pay(orderId, request, response);
return "mall/order/list";
}
/**
* 确认收货
* @param orderId
* @param response
* @return
* @throws IOException
*/
@RequestMapping("receive.do")
@ResponseBody
public ResultBean<Boolean> receive(int orderId, HttpServletResponse response) throws IOException {
orderService.receive(orderId);
return new ResultBean<>(true);
}
/**
* create by: Cillivian
* description:分页显示
* create time: 22:26 2022/4/13 0013
*
* @Param: null
* @return
*/
@ResponseBody
@RequestMapping("/getTotal.do")
public ResultBean<Integer> getTotal() {
Pageable pageable = PageRequest.of(1, 15, Sort.by(Sort.Direction.ASC,"id"));
int total = (int) orderService.findAll(pageable).getTotalElements();
return new ResultBean<>(total);
}
}
pom.xml代码文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.scut</groupId>
<artifactId>mall</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mall</name>
<description>QQ211811 9173 java程序猿 好乐思玩具</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--log4j 2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--druid连接池 mybatis-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!--aop 切面-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--controller -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--html模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--SpringBoot2.0thymeleaf布局模块 -->
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<!--热加载代码方便调试用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!--测试框架-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
<!--JSON-->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.9.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven-ali</id>
<url>http://maven.aliyun.com/nexus/content/groups/public//</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
</project>