📅  最后修改于: 2023-12-03 15:17:31.605000             🧑  作者: Mango
本文介绍了使用Java语言开发Mambalam Srardham在线预订系统的方法和技术。
CREATE TABLE users(
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL
);
CREATE TABLE stations(
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
CREATE TABLE routes(
id INT PRIMARY KEY,
origin_id INT NOT NULL,
destination_id INT NOT NULL,
price DOUBLE NOT NULL,
FOREIGN KEY (origin_id) REFERENCES stations(id) ON DELETE RESTRICT,
FOREIGN KEY (destination_id) REFERENCES stations(id) ON DELETE RESTRICT
);
CREATE TABLE orders(
id INT PRIMARY KEY,
user_id INT NOT NULL,
route_id INT NOT NULL,
price DOUBLE NOT NULL,
is_paid BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT,
FOREIGN KEY (route_id) REFERENCES routes(id) ON DELETE RESTRICT
);
以下是订单控制器中添加订单的代码片段:
@PostMapping("/orders")
public String addOrder(@RequestParam Integer userId, @RequestParam Integer routeId, Model model) {
User user = userService.getUserById(userId);
Route route = routeService.getRouteById(routeId);
Order order = orderService.addOrder(user, route);
String message = "Order added successfully. Order ID: " + order.getId();
model.addAttribute("message", message);
return "order-result";
}
以下是添加订单的HTML页面代码片段:
<form method="POST" action="/orders">
<input type="hidden" name="userId" value="1">
<select name="routeId">
<option value="1">Route 1</option>
<option value="2">Route 2</option>
<option value="3">Route 3</option>
</select>
<button type="submit">Add to cart</button>
</form>
本文介绍了使用Java和Spring Boot开发Mambalam Srardham在线预订系统的方法和技术。我们了解了如何设计数据库模式、实现后端和前端功能,并实现了购物车和支付功能。通过应用这些知识,我们可以开发出更加完善和易用的在线预订系统。