<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hspedu.springboot.mybatis.mapper.MonsterMapper">
<insert id="insertReservation" parameterType="Reservation">
INSERT INTO reservations (room_id, user_id, start_time, end_time, topic)
VALUES (#{roomId}, #{userId}, #{startTime}, #{endTime}, #{topic})
<selectKey keyProperty="reservationId" resultType="int" order="AFTER">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
<delete id="deleteReservation" parameterType="int">
DELETE FROM reservations WHERE reservation_id = #{reservationId}
</delete>
<select id="selectReservation" resultType="Reservation" parameterType="int">
SELECT reservation_id as reservationId, room_id as roomId, user_id as userId, start_time as startTime, end_time as endTime, topic
FROM reservations
WHERE reservation_id = #{reservationId}
</select>
<select id="selectAllReservations" resultType="Reservation">
SELECT reservation_id as reservationId, room_id as roomId, user_id as userId, start_time as startTime, end_time as endTime, topic
FROM reservations
</select>
<update id="updateReservation" parameterType="Reservation">
UPDATE reservations
SET room_id = #{roomId},
user_id = #{userId},
start_time = #{startTime},
end_time = #{endTime},
topic = #{topic}
WHERE reservation_id = #{reservationId}
</update>
<select id="selectReservationsByTimeRange" resultType="Reservation">
SELECT reservation_id, room_id, user_id, start_time, end_time, topic
FROM reservations
WHERE start_time <= #{endTime} AND end_time >= #{startTime}
</select>
<select id="selectReservationByRoomID" resultType="Reservation" parameterType="int">
SELECT reservation_id as reservationId, room_id as roomId, user_id as userId, start_time as startTime, end_time as endTime, topic
FROM reservations
WHERE room_id = #{roomId}
</select>
</mapper>
private Integer reservationId;
private Integer roomId;
private Integer userId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
private String topic;
private String start;
private String end;
private int roomId;
private String title;