AlipayConfig
package com.example.config;
public class AlipayConfig {
public static String app_id ="";
public static String merchant_private_key = "";
public static String alipay_public_key = "";
public static String notify_url = "";
public static String return_url = "";
public static String sign_type = "RSA2";
public static String charset = "utf-8";
public static String gatewayUrl = "";
}
AliPayController.java
package com.example.controller;
import com.alipay.api.AlipayApiException;
import com.example.entity.Flow;
import com.example.entity.Orders;
import com.example.service.IAliPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
@Controller
@RequestMapping("")
public class AliPayController {
@Autowired
private IAliPayService aliPayService;
@PostMapping("pay")
@ResponseBody
public String pay(Orders orders){
return aliPayService.pay(orders);
}
}
FlowController.java
package com.example.controller;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.example.config.AlipayConfig;
import com.example.entity.Flow;
import com.example.entity.Orders;
import com.example.service.IFlowService;
import com.example.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
@Controller
@RequestMapping("/flow")
public class FlowController {
@Autowired
private IOrdersService ordersService;
@Autowired
private IFlowService flowService;
@GetMapping("alipayReturnNotice")
public ModelAndView save(HttpServletRequest request) throws UnsupportedEncodingException {
System.out.println("同步请求,支付成功后,支付宝的返回数据是:" + request);
String orderNum = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"), "UTF-8");
String tradeNo = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"), "UTF-8");
String payPrice = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"), "UTF-8");
System.out.println("return orderNum:" + orderNum);
System.out.println("return tradeNo:" + tradeNo);
System.out.println("return payPrice:" + payPrice);
Orders orders = ordersService.getByNumber(orderNum);
Flow flow = new Flow();
flow.setOrderId(orders.getId());
flow.setOrderNum(orderNum);
flow.setFlowNum(tradeNo);
flow.setPaidAmount(payPrice);
flow.setCreateTime(LocalDateTime.now());
flow.setProductId(orders.getProductId());
flow.setBuyCounts(orders.getBuyCounts());
boolean result = flowService.saveFlow(flow,orders);
ModelAndView mav = new ModelAndView("flow_detail");
mav.addObject("flow",flow);
mav.addObject("orders",orders);
return mav;
}
}
OrdersController.java
package com.example.controller;
import com.example.entity.Orders;
import com.example.entity.Product;
import com.example.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@Controller
@RequestMapping("")
public class OrdersController {
@Autowired
private IOrdersService ordersService;
@PostMapping("orders")
public ModelAndView saveOrder(Orders orders){
boolean result = ordersService.saveOrders(orders);
System.out.println("订单添加结果:" + result);
System.out.println("订单信息是:" + orders);
ModelAndView mav =new ModelAndView("order_detail");
mav.addObject("orders",orders);
return mav;
}
}
ProductController.java
package com.example.controller;
import com.example.entity.Product;
import com.example.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
@RequestMapping("")
public class ProductController {
@Autowired
private IProductService productService;
@GetMapping("product")
public ModelAndView getAll(){
ModelAndView mav = new ModelAndView("product_list");
List<Product> products = productService.list();
mav.addObject("products",products);
return mav;
}
@GetMapping("product/{id}")
public ModelAndView getById(@PathVariable("id")Integer proId){
ModelAndView mav = new ModelAndView("product_detail");
Product product = productService.getById(proId);
mav.addObject("product",product);
return mav;
}
}
UserController.java
package com.example.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
@Controller
@RequestMapping("/user")
public class UserController {
}
Flow.java
package com.example.entity;
import java.io.Serializable;
import java.time.LocalDateTime;
public class Flow implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String flowNum;
private String orderNum;
private String productId;
private String paidAmount;
private Integer paidMethod;
private Integer buyCounts;
private LocalDateTime createTime;
private String orderId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFlowNum() {
return flowNum;
}
public void setFlowNum(String flowNum) {
this.flowNum = flowNum;
}
public String getOrderNum() {
return orderNum;
}
public void setOrderNum(String orderNum) {
this.orderNum = orderNum;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getPaidAmount() {
return paidAmount;
}
public void setPaidAmount(String paidAmount) {
this.paidAmount = paidAmount;
}
public Integer getPaidMethod() {
return paidMethod;
}
public void setPaidMethod(Integer paidMethod) {
this.paidMethod = paidMethod;
}
public Integer getBuyCounts() {
return buyCounts;
}
public void setBuyCounts(Integer buyCounts) {
this.buyCounts = buyCounts;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
@Override
public String toString() {
return "Flow{" +
"id=" + id +
", flowNum=" + flowNum +
", orderNum=" + orderNum +
", productId=" + productId +
", paidAmount=" + paidAmount +
", paidMethod=" + paidMethod +
", buyCounts=" + buyCounts +
", createTime=" + createTime +
", orderId=" + orderId +
"}";
}
}
Orders.java
package com.example.entity;
import java.io.Serializable;
import java.time.LocalDateTime;
public class Orders implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String orderNum;
private String orderStatus;
private Float orderPrice;
private String paidAmount;
private String productId;
private Integer buyCounts;
private LocalDateTime createTime;
private String proName;
private Float proPrice;
private Integer userId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOrderNum() {
return orderNum;
}
public void setOrderNum(String orderNum) {
this.orderNum = orderNum;
}
public String getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(String orderStatus) {
this.orderStatus = orderStatus;
}
public Float getOrderPrice() {
return orderPrice;
}
public void setOrderPrice(Float orderPrice) {
this.orderPrice = orderPrice;
}
public String getPaidAmount() {
return paidAmount;
}
public void setPaidAmount(String paidAmount) {
this.paidAmount = paidAmount;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public Integer getBuyCounts() {
return buyCounts;
}
public void setBuyCounts(Integer buyCounts) {
this.buyCounts = buyCounts;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public String getProName() {
return proName;
}
public void setProName(String proName) {
this.proName = proName;
}
public Float getProPrice() {
return proPrice;
}
public void setProPrice(Float proPrice) {
this.proPrice = proPrice;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@Override
public String toString() {
return "Orders{" +
"id=" + id +
", orderNum=" + orderNum +
", orderStatus=" + orderStatus +
", orderPrice=" + orderPrice +
", paidAmount=" + paidAmount +
", productId=" + productId +
", buyCounts=" + buyCounts +
", createTime=" + createTime +
", proName=" + proName +
", proPrice=" + proPrice +
", userId=" + userId +
"}";
}
}
Product.java
package com.example.entity;
import java.io.Serializable;
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String name;
private Float price;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
@Override
public String toString() {
return "Product{" +
"id=" + id +
", name=" + name +
", price=" + price +
"}";
}
}
User.java
package com.example.entity;
import java.io.Serializable;
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String username;
private String sex;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username=" + username +
", sex=" + sex +
"}";
}
}
FlowMapper.java
package com.example.mapper;
import com.example.entity.Flow;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface FlowMapper extends BaseMapper<Flow> {
}
OrdersMapper.java
package com.example.mapper;
import com.example.entity.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface OrdersMapper extends BaseMapper<Orders> {
}
ProductMapper.java
package com.example.mapper;
import com.example.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface ProductMapper extends BaseMapper<Product> {
}
UserMapper.java
package com.example.mapper;
import com.example.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface UserMapper extends BaseMapper<User> {
}
AliPayServiceImpl.java
package com.example.service.impl;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.example.config.AlipayConfig;
import com.example.entity.Orders;
import com.example.service.IAliPayService;
import org.springframework.stereotype.Service;
@Service
public class AliPayServiceImpl implements IAliPayService {
@Override
public String pay(Orders orders){
String orderNum = orders.getOrderNum();
Float orderPrice = orders.getOrderPrice();
String orderId = orders.getId();
String proName = orders.getProName();
String proId = orders.getProductId();
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("" );
String timeout_express = "1c";
String body="";
alipayRequest.setBizContent("{\"out_trade_no\":\"" + orderNum + "\","
+ "\"total_amount\":\"" + orderPrice + "\","
+ "\"subject\":\"" + proName + "\","
+ "\"body\":\"" + body + "\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
String result = null;
try {
result = alipayClient.pageExecute(alipayRequest).getBody();
} catch (AlipayApiException e) {
System.out.println("支付有异常");
throw new RuntimeException(e);
}
System.out.println("执行支付请求后,result:" + result);
return result;
}
}
FlowServiceImpl.java
package com.example.service.impl;
import com.example.entity.Flow;
import com.example.entity.Orders;
import com.example.mapper.FlowMapper;
import com.example.mapper.OrdersMapper;
import com.example.service.IFlowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class FlowServiceImpl implements IFlowService {
@Autowired
private FlowMapper flowMapper;
@Autowired
private OrdersMapper ordersMapper;
@Transactional
public boolean saveFlow(Flow flow, Orders orders) {
int flowRows = flowMapper.insert(flow);
if(flowRows >0){
orders.setOrderStatus("1");
int orderRows = ordersMapper.updateById(orders);
return orderRows >0;
}
return false;
}
}
OrdersServiceImpl.java
package com.example.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.Orders;
import com.example.mapper.OrdersMapper;
import com.example.service.IOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@Service
public class OrdersServiceImpl implements IOrdersService {
@Autowired
private OrdersMapper ordersMapper;
@Override
public boolean saveOrders(Orders orders){
orders.setOrderNum(UUID.randomUUID().toString().replace("-",""));
orders.setOrderStatus("0");
orders.setCreateTime(LocalDateTime.now());
int rows = ordersMapper.insert(orders);
return rows>0;
}
@Override
public Orders getByNumber(String orderNumber) {
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_num",orderNumber);
return ordersMapper.selectOne(queryWrapper);
}
}
ProductServiceImpl.java
package com.example.service.impl;
import com.example.entity.Product;
import com.example.mapper.ProductMapper;
import com.example.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
}
UserServiceImpl.java
package com.example.service.impl;
import com.example.entity.User;
import com.example.mapper.UserMapper;
import com.example.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
}
alipay.sql
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `flow`;
CREATE TABLE `flow` (
`id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`flow_num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '流水号',
`order_num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '订单号',
`product_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '产品主键ID',
`paid_amount` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '支付金额',
`paid_method` int(0) NULL DEFAULT NULL COMMENT '支付方式\r\n 1:支付宝\r\n 2:微信',
`buy_counts` int(0) NULL DEFAULT NULL COMMENT '购买个数',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`order_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '流水表' ROW_FORMAT = Compact;
INSERT INTO `flow` VALUES ('1658997929823645697', NULL, 'b3de9207055242c2b55c16d281f5117a', '201', '30.00', NULL, 3, '2023-05-18 08:48:24', NULL);
INSERT INTO `flow` VALUES ('1659000347818930178', NULL, '4754166daf0b4a3f929d7cfa2fd34144', '204', '17.60', NULL, 2, '2023-05-18 08:58:00', NULL);
INSERT INTO `flow` VALUES ('1659000586453856258', NULL, 'b836abcde23c485f82b562595cf9a444', '203', '21.00', NULL, 6, '2023-05-18 08:58:57', NULL);
INSERT INTO `flow` VALUES ('1659004599899467777', '2023051822001488720502559317', 'cc6ca6569aa042acadd5d6722769d851', '203', '10.50', NULL, 3, '2023-05-18 09:14:54', NULL);
INSERT INTO `flow` VALUES ('1659010430405652482', '2023051822001488720502559834', '612c16a1b88248ce994fd8f78e381f9f', '201', '10.00', NULL, 1, '2023-05-18 09:38:04', NULL);
INSERT INTO `flow` VALUES ('1659013287892692993', '2023051822001488720502559836', 'd6d900ada2474c03994331d5ac572996', '201', '10.00', NULL, 1, '2023-05-18 09:49:25', NULL);
INSERT INTO `flow` VALUES ('1659015578301444098', '2023051822001488720502559836', 'd6d900ada2474c03994331d5ac572996', '201', '10.00', NULL, 1, '2023-05-18 09:58:31', NULL);
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`order_num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '订单号',
`order_status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '订单状态\r\n 10:待付款\r\n 20:已付款',
`order_price` float(11, 0) NULL DEFAULT NULL COMMENT '订单金额',
`paid_amount` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '实际支付金额',
`product_id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '产品表外键ID',
`buy_counts` int(0) NULL DEFAULT NULL COMMENT '产品购买的个数',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '订单创建时间',
`pro_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '支付时间',
`pro_price` float(10, 2) NULL DEFAULT NULL,
`user_id` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '订单表' ROW_FORMAT = Compact;
INSERT INTO `orders` VALUES ('1658997691247439874', 'b3de9207055242c2b55c16d281f5117a', '1', 30, NULL, '201', 3, '2023-05-18 08:47:27', 'milk', 10.00, 1);
INSERT INTO `orders` VALUES ('1659000133737459713', '4754166daf0b4a3f929d7cfa2fd34144', '1', 18, NULL, '204', 2, '2023-05-18 08:57:09', '清风面纸', 8.80, 1);
INSERT INTO `orders` VALUES ('1659000395994705921', 'b836abcde23c485f82b562595cf9a444', '1', 21, NULL, '203', 6, '2023-05-18 08:58:12', '冰红茶', 3.50, 1);
INSERT INTO `orders` VALUES ('1659004376556974081', 'cc6ca6569aa042acadd5d6722769d851', '1', 10, NULL, '203', 3, '2023-05-18 09:14:01', '冰红茶', 3.50, 2);
INSERT INTO `orders` VALUES ('1659006193118425089', '612c16a1b88248ce994fd8f78e381f9f', '1', 10, NULL, '201', 1, '2023-05-18 09:21:14', 'milk', 10.00, 2);
INSERT INTO `orders` VALUES ('1659012787835187202', 'd6d900ada2474c03994331d5ac572996', '1', 10, NULL, '201', 1, '2023-05-18 09:47:26', 'milk', 10.00, 2);
DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
`id` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '产品名称',
`price` float(11, 2) NULL DEFAULT NULL COMMENT '价格',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '产品表 ' ROW_FORMAT = Compact;
INSERT INTO `product` VALUES ('201', 'milk', 10.00);
INSERT INTO `product` VALUES ('202', 'apple', 6.00);
INSERT INTO `product` VALUES ('203', '冰红茶', 3.50);
INSERT INTO `product` VALUES ('204', '清风面纸', 8.80);
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户表' ROW_FORMAT = Compact;
INSERT INTO `user` VALUES ('1', 'tom', 'F');
INSERT INTO `user` VALUES ('2', 'smith', 'F');
SET FOREIGN_KEY_CHECKS = 1;
application.yaml
server:
servlet:
context-path: /app
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/alipay?serverTimezone=Asia/Shanghai
username: root
password: 123456
mvc:
view:
prefix: /
suffix: .jsp
flow_detail.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>流水详情</h2>
订单编号是:${orders.orderNum} <br>
交易流水号:${flow.flowNum} <br>
购买的商品:${orders.proName} <br>
购买的原价:${orders.proPrice} <br>
购买的数量:${orders.buyCounts} <br>
实际支付金额 ${flow.paidAmount} <br>
支付时间是${flow.createTime} <br>
<a href="${pageContext.request.contextPath}/orders?userId=1">我的所有订单</a>
</body>
</html>
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/product">查询所有的商品</a>
</body>
</html>
order_detail.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
</head>
<body>
<h2>订单详情页面</h2>
<form method="post" action="${pageContext.request.contextPath}/pay" >
<input type="hidden" name="orderId" class="orderId" value="${orders.id}"> <br>
<input type="hidden" name="productId" class="proId" value="${orders.productId}"> <br>
订单编号:<input type="text" name="orderNum" class="orderNum" value="${orders.orderNum}"> <br>
购买的商品:<input type="text" name="proName" class="proName" value="${orders.proName}"> <br>
订单总价:<input type="text" name="orderPrice" class="orderPrice" value="${orders.orderPrice}"> <br>
<input type="submit" value="去支付" class="payBtn">
</form>
</body>
</html>
order_list.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>我的所有订单</h2>
<ul>
<c:forEach var="order" items="${ordersList}">
<li>
订单编号:${order.orderNum} <br>
商品名称:${order.proName} <br>
商品原价:${order.proPrice} <br>
购买数量:${order.buyCounts} <br>
订单金额:${order.orderPrice} <br>
订单状态:
<c:if test="${order.orderStatus ==0}">
未支付
</c:if>
<c:if test="${order.orderStatus ==1}">
已支付
</c:if>
<c:if test="${order.orderStatus ==2}">
已取消
</c:if>
<hr>
</li>
</c:forEach>
</ul>
</body>
</html>
product_detail.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>商品详情</h2>
<form action="${pageContext.request.contextPath}/orders" method="post">
<input type="hidden" name="userId" value="1">
商品id:<input type="text" name="productId" value="${product.id}" readonly><br>
商品名称:<input type="text"name="proName" value="${product.name}" readonly><br>
商品价格:<input type="text" name="orderPrice" value="${product.price}" readonly><br>
购买数量:<input type="text" name="buyCounts" value="1"><br>
<input type="submit" value="确认订单">
</form>
</body>
</html>
product_list.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>商品列表</h2>
<c:forEach var="product" items="${products}">
商品名称:${product.name}
商品价格:${product.price}
<a href="${pageContext.request.contextPath}/product/${product.id}">购买</a> <br>
</c:forEach>
</body>
</html>
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>Payment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Payment</name>
<description>Payment</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>