这是一个基于JSP、Java、Spring MVC、MySQL和MyBatis的Web酒店预约管理系统的开发示例。以下是一些核心代码片段和配置示例:
数据库配置 (mybatis-config.xml)
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/hotel_reservation_system"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/example/mapper/ReservationMapper.xml"/>
<!-- 其他Mapper配置 -->
</mappers>
</configuration>
实体类 (Reservation.java)
public class Reservation {
private Integer id;
private String roomType;
private Date checkInDate;
private Date checkOutDate;
private String customerName;
private String contactNumber;
private String email;
// getters and setters
}
Mapper接口 (ReservationMapper.java)
public interface ReservationMapper {
int insertReservation(Reservation reservation);
List<Reservation> getAllReservations();
// 其他方法定义
}
Service层 (ReservationService.java)
@Service
public class ReservationService {
@Autowired
private ReservationMapper reservationMapper;
public void makeReservation(Reservation reservation) {
reservationMapper.insertReservation(reservation);
}
public List<Reservation> getAllReservations() {
return reservationMapper.getAllReservations();
}
// 其他方法实现
}
Controller层 (ReservationController.java)
@Controller
@RequestMapping("/reservation")
public class ReservationController {
@Autowired
private ReservationService reservationService;
@PostMapping("/make")
public String makeReservation(Reservation reservation) {
reservationService.makeReservation(reservation);
return "redirect:/reservation/list";
}
@GetMapping("/list")
public