使用xml配置记得把mapper.xml放入mybatis_mapper.xml
dao层调用方法时,记的别传空List!!!
即使主键是自动递增的也要加上去!!!
<sql id='addColumn'>
ID,
ATTENDANCE_DATE,
CARD_NUMBER,
PERSON_CODE,
PERSON_NAME,
DEPT_NAME,
FIRST_ATTENDANCE_TIME,
FIRST_ATTENDANCE_TEMP,
LAST_ATTENDANCE_TIME,
LAST_ATTENDANCE_TEMP
</sql>
<sql id='addValue'>
#{id,jdbcType=NUMERIC}
#{attendanceDate,jdbcType=DATE},
#{cardNumber,jdbcType=VARCHAR},
#{personCode,jdbcType=VARCHAR},
#{personName,jdbcType=VARCHAR},
#{deptName,jdbcType=VARCHAR},
#{firstAttendanceTime,jdbcType=VARCHAR},
#{firstAttendanceTemp,jdbcType=VARCHAR},
#{lastAttendanceTime,jdbcType=VARCHAR},
#{lastAttendanceTemp,jdbcType=VARCHAR}
</sql>
<sql id='batchAddValue'>
#{item.id,jdbcType=NUMERIC},
#{item.attendanceDate,jdbcType=DATE},
#{item.cardNumber,jdbcType=VARCHAR},
#{item.personCode,jdbcType=VARCHAR},
#{item.personName,jdbcType=VARCHAR},
#{item.deptName,jdbcType=VARCHAR},
#{item.firstAttendanceTime,jdbcType=VARCHAR},
#{item.firstAttendanceTemp,jdbcType=VARCHAR},
#{item.lastAttendanceTime,jdbcType=VARCHAR},
#{item.lastAttendanceTemp,jdbcType=VARCHAR}
</sql>
批量插入
<insert id="batchAddTimeAttendance" parameterType="TimeAttendance">
INSERT INTO time_attendance
(<include refid="addColumn"/>)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
<include refid="batchAddValue"/>
)
</foreach>
</insert>
批量修改
<update id="batchUpdateTimeAttendance" parameterType="TimeAttendance">
<foreach collection="list" item="item" index="index" separator=";">
UPDATE time_attendance
<set>
<if test="item.attendanceDate != null">
ATTENDANCE_DATE = #{item.attendanceDate},
</if>
<if test="item.cardNumber != null">
CARD_NUMBER = #{item.cardNumber},
</if>
<if test="item.personName != null">
PERSON_NAME = #{item.personName},
</if>
<if test="item.deptName != null">
DEPT_NAME = #{item.deptName},
</if>
<if test="item.firstAttendanceTime != null">
FIRST_ATTENDANCE_TIME = #{item.firstAttendanceTime},
</if>
<if test="item.firstAttendanceTemp != null">
FIRST_ATTENDANCE_TEMP = #{item.firstAttendanceTemp},
</if>
<if test="item.lastAttendanceTime != null">
LAST_ATTENDANCE_TIME = #{item.lastAttendanceTime},
</if>
<if test="item.lastAttendanceTemp != null">
LAST_ATTENDANCE_TEMP = #{item.lastAttendanceTemp}
</if>
</set>
WHERE PERSON_CODE = #{item.personCode}
</foreach>
</update>
批量删除
<delete id="" parameterType="Map">
DELETE FROM 表名
<where>
AND ID IN
<foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
#{item}
</foreach>
</where>
</delete>