帮我生成新增的mapper.xml
时间: 2024-10-13 21:08:00 浏览: 26
当然可以,这里是一个简单的Mapper XML文件示例,对应于之前我们提到的`ReservationMapper`接口。这个XML文件通常会包含在MyBatis的`resources/mapper`目录下:
```xml
<?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.yourproject.mapper.ReservationMapper">
<!-- 插入新记录 -->
<insert id="insertNewReservation" parameterType="com.yourproject.entity.Reservation">
INSERT INTO reservation
(name, mobile, time, visitor, type, status, create_time, update_time, create_by, update_by, remark)
VALUES
(#{name}, #{mobile}, #{time}, #{visitor}, #{type}, #{status}, NOW(), NULL, #{createBy}, #{updateBy}, #{remark})
</insert>
<!-- 更新记录 -->
<update id="updateReservationById" parameterType="com.yourproject.entity.Reservation">
UPDATE reservation
SET name = #{name},
mobile = #{mobile},
time = #{time},
visitor = #{visitor},
type = #{type},
status = #{status},
update_time = NOW(),
update_by = #{updateBy},
remark = #{remark}
WHERE id = #{id} AND mobile = #{mobile} AND time = #{time}
</update>
<!-- 查询单条记录 -->
<select id="getReservationByMobileAndTime" parameterType="map" resultType="com.yourproject.entity.Reservation">
SELECT * FROM reservation
WHERE mobile = #{mobile} AND time = #{time}
</select>
<!-- 删除记录 -->
<delete id="deleteReservationById" parameterType="long">
DELETE FROM reservation
WHERE id = #{id}
</delete>
<!-- 查询总数 -->
<resultMap id="totalCountResult" type="int">
SELECT COUNT(*)
</resultMap>
<select id="countReservationsByStatus" resultMap="totalCountResult">
SELECT COUNT(*) FROM reservation WHERE status IN (0, 1)
</select>
<!-- 分页查询 -->
<resultMap id="listResult" type="com.yourproject.entity.Reservation">
SELECT * FROM reservation
ORDER BY create_time DESC
</resultMap>
<select id="listReservationsWithPagination" parameterType="map" resultMap="listResult">
SELECT * FROM reservation
LIMIT #{offset}, #{limit}
</select>
</mapper>
```
阅读全文