基于spring boot的酒店管理系统
时间: 2023-11-21 16:06:17 浏览: 146
基于springboot的酒店管理系统
基于Spring Boot的酒店管理系统可以实现类似于引用和引用中所描述的功能。具体来说,可以使用Spring Boot框架搭建一个Web应用程序,使用MySQL数据库存储数据,并使用Thymeleaf模板引擎生成动态网页。以下是该系统的一些功能模块:
1.用户登录和注册模块
```java
@Controller
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/login")
public String login() {
return "login";
}
@PostMapping("/login")
public String login(@RequestParam String username, @RequestParam String password, HttpSession session) {
User user = userService.login(username, password);
if (user != null) {
session.setAttribute("user", user);
return "redirect:/index";
} else {
return "login";
}
}
@GetMapping("/register")
public String register() {
return "register";
}
@PostMapping("/register")
public String register(@RequestParam String username, @RequestParam String password, @RequestParam String email) {
User user = new User(username, password, email);
userService.register(user);
return "redirect:/login";
}
}
```
2.客房信息管理模块
```java
@Controller
public class RoomController {
@Autowired
private RoomService roomService;
@GetMapping("/room")
public String room(Model model) {
List<Room> rooms = roomService.getAllRooms();
model.addAttribute("rooms", rooms);
return "room";
}
@GetMapping("/room/add")
public String addRoom() {
return "add_room";
}
@PostMapping("/room/add")
public String addRoom(@RequestParam String roomNumber, @RequestParam String roomType, @RequestParam String price) {
Room room = new Room(roomNumber, roomType, Double.parseDouble(price));
roomService.addRoom(room);
return "redirect:/room";
}
@GetMapping("/room/delete/{id}")
public String deleteRoom(@PathVariable Long id) {
roomService.deleteRoom(id);
return "redirect:/room";
}
}
```
3.客房预订管理模块
```java
@Controller
public class BookingController {
@Autowired
private BookingService bookingService;
@GetMapping("/booking")
public String booking(Model model) {
List<Booking> bookings = bookingService.getAllBookings();
model.addAttribute("bookings", bookings);
return "booking";
}
@GetMapping("/booking/add")
public String addBooking() {
return "add_booking";
}
@PostMapping("/booking/add")
public String addBooking(@RequestParam String roomNumber, @RequestParam String customerName, @RequestParam String checkInDate, @RequestParam String checkOutDate) {
Booking booking = new Booking(roomNumber, customerName, LocalDate.parse(checkInDate), LocalDate.parse(checkOutDate));
bookingService.addBooking(booking);
return "redirect:/booking";
}
@GetMapping("/booking/delete/{id}")
public String deleteBooking(@PathVariable Long id) {
bookingService.deleteBooking(id);
return "redirect:/booking";
}
}
```
阅读全文