基于javaweb+mysql的springboot酒店管理系统(java+springboot+maven+mybatis-plus+html+thymleaf+mysql)
以下是一个简化的酒店管理系统的核心功能代码示例,包括客房管理和客户管理。
// 客房管理Controller
@RestController
@RequestMapping("/rooms")
public class RoomController {
@Autowired
private RoomService roomService;
// 获取所有客房
@GetMapping
public List<Room> getAllRooms() {
return roomService.getAllRooms();
}
// 根据ID获取客房
@GetMapping("/{id}")
public Room getRoomById(@PathVariable("id") Long id) {
return roomService.getRoomById(id);
}
// 添加客房
@PostMapping
public Room addRoom(@RequestBody Room room) {
return roomService.addRoom(room);
}
// 更新客房
@PutMapping("/{id}")
public Room updateRoom(@PathVariable("id") Long id, @RequestBody Room room) {
room.setId(id);
return roomService.updateRoom(room);
}
// 删除客房
@DeleteMapping("/{id}")
public void deleteRoom(@PathVariable("id") Long id) {
roomService.deleteRoom(id);
}
}
// 客户管理Controller
@RestController
@RequestMapping("/customers")
public class CustomerController {
@Autowired
private CustomerService customerService;
// 获取所有客户
@GetMapping
public List<Customer> getAllCustomers() {
return customerService.getAllCustomers();
}
// 根据ID获取客户
@GetMapping("/{id}")
public Customer getCustomerById(@PathVariable("id") Long id) {
return customerService.getCustomerById(id);
}
// 添加客户
@PostMapping
public Customer addCustomer(@RequestBody Customer customer) {
return customerService.addCustomer(customer);
}
// 更新客户
@PutMapping("/{id}")
public Customer updateCustomer(@PathVariable("id") Long id, @RequestBody Customer customer) {
customer.setId(id);
return customerService.updateCustomer(customer);
}
// 删除客户
@DeleteMapping("/{id}")
public void deleteCustomer(@PathVariable("id") Long id) {
customerService.deleteCustomer(id);
}
}
这个示例展示了如何使用Spring Boot创建RESTful API来管理客房和客户。每个Controller都包含了基本的CRUD操作,并且使用了Spring的依赖注入和注解来简化代码。这个示例假设有对应的RoomService
和CustomerService
服务层,以及Room
和Customer
实体类。在实际的项目中,你还
评论已关闭