引言
文献综述
系统设计
系统实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flower Shop</title>
<!-- 引入Bootstrap样式 -->
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="app">
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Flower Shop</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" @click="changePage('home')">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" @click="changePage('products')">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" @click="changePage('cart')">Shopping Cart</a>
</li>
<li class="nav-item">
<a class="nav-link" @click="changePage('orders')">My Orders</a>
</li>
</ul>
</div>
</nav>
<!-- 页面内容 -->
<div class="container mt-3">
<div v-if="currentPage === 'home'">
<h2>Welcome to Flower Shop</h2>
<!-- 网站首页内容 -->
</div>
<div v-else-if="currentPage === 'products'">
<h2>Products</h2>
<!-- 展示鲜花商品列表 -->
<div v-for="flower in flowers" :key="flower.id" class="card mb-3">
<img :src="flower.imageUrl" class="card-img-top" alt="Flower Image">
<div class="card-body">
<h5 class="card-title">{{ flower.name }}</h5>
<p class="card-text">Price: ${{ flower.price.toFixed(2) }}</p>
<button @click="addToCart(flower)" class="btn btn-primary">Add to Cart</button>
</div>
</div>
</div>
<div v-else-if="currentPage === 'cart'">
<h2>Shopping Cart</h2>
<!-- 展示购物车内容 -->
<div v-if="cart.length === 0">
<p>Your shopping cart is empty.</p>
</div>
<div v-else>
<div v-for="item in cart" :key="item.flower.id" class="card mb-3">
<div class="card-body">
<h5 class="card-title">{{ item.flower.name }}</h5>
<p class="card-text">Price: ${{ item.flower.price.toFixed(2) }}</p>
<p class="card-text">Quantity: {{ item.quantity }}</p>
<button @click="removeFromCart(item)" class="btn btn-danger">Remove</button>
</div>
</div>
<p>Total: ${{ calculateTotal().toFixed(2) }}</p>
<button @click="checkout" class="btn btn-success">Checkout</button>
</div>
</div>
<div v-else-if="currentPage === 'orders'">
<h2>My Orders</h2>
<!-- 展示用户订单列表 -->
<div v-if="orders.length === 0">
<p>You have no orders yet.</p>
</div>
<div v-else>
<div v-for="order in orders" :key="order.id" class="card mb-3">
<div class="card-body">
<h5 class="card-title">Order ID: {{ order.id }}</h5>
<p class="card-text">Total: ${{ order.totalAmount.toFixed(2) }}</p>
<p class="card-text">Status: {{ order.status }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 引入Vue.js -->
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
<script>
new Vue({
el
-- 商品表
CREATE TABLE Flowers (
FlowerID INT PRIMARY KEY AUTO_INCREMENT,
FlowerName VARCHAR(100) NOT NULL,
Price DECIMAL(10, 2) NOT NULL,
Stock INT NOT NULL,
Description TEXT,
ImageURL VARCHAR(255)
);
-- 订单表
CREATE TABLE Orders (
OrderID INT PRIMARY KEY AUTO_INCREMENT,
UserID INT,
OrderDate DATETIME DEFAULT CURRENT_TIMESTAMP,
TotalAmount DECIMAL(10, 2) NOT NULL,
Status VARCHAR(20) DEFAULT 'Pending', -- 订单状态:Pending, Shipped, Delivered, Canceled
FOREIGN KEY (UserID) REFERENCES Users(UserID)
);
-- 订单详情表
CREATE TABLE OrderDetails (
OrderDetailID INT PRIMARY KEY AUTO_INCREMENT,
OrderID INT,
FlowerID INT,
Quantity INT NOT NULL,
Subtotal DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (OrderID) REFERENCES Orders(OrderID),
FOREIGN KEY (FlowerID) REFERENCES Flowers(FlowerID)
);
-- 用户表
CREATE TABLE Users (
UserID INT PRIMARY KEY AUTO_INCREMENT,
Username VARCHAR(50) NOT NULL,
Password VARCHAR(255) NOT NULL,
Email VARCHAR(100) NOT NULL,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Address VARCHAR(255)
);
// Order.java
@Entity
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private User user;
private LocalDateTime orderDate;
private BigDecimal totalAmount;
private String status;
// Getters and setters
}
// OrderRepository.java
public interface OrderRepository extends JpaRepository<Order, Long> {
List<Order> findByUser(User user);
}
// OrderService.java
@Service
public class OrderService {
@Autowired
private OrderRepository orderRepository;
public List<Order> getAllOrders() {
return orderRepository.findAll();
}
public List<Order> getOrdersByUser(User user) {
return orderRepository.findByUser(user);
}
// Other CRUD operations and business logic
}
// User.java
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
private String email;
private String firstName;
private String lastName;
private String address;
// Getters and setters
}
// UserRepository.java
public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(String username);
}
// UserService.java
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public User getUserById(Long id) {
return userRepository.findById(id).orElse(null);
}
public User getUserByUsername(String username) {
return userRepository.findByUsername(username);
}
// Other CRUD operations and business logic
}
系统测试
实验结果与分析
系统实现页面展示:
讨论与展望
结论
参考文献