1.批量增加:
1.1,
<!-- 新增子任务 -->
<insert id = "insertDeviceTaskList" parameterType = "java.util.List">
insert into device_task(
SUBJECT,STATUS,OUTPUT,REMARK,PROGRESS,
PLAN_WORK_TIME,REAL_WORK_TIME,
PLAN_DURATION,REAL_DURATION,
PLAN_START_TIME,
PLAN_END_TIME,REAL_START_TIME,REAL_END_TIME,
PROJECT_ID,FATHER_TASK,
CHILD_TASK,IS_ADD,GRADE,TASK_TYPE,RELATION_TASK,
CREATE_TIME
) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.subject},#{item.status},#{item.output},
#{item.remark},#{item.progress},
#{item.planWorkTime},#{item.realWorkTime},#{item.planDuration},#{item.realDuration},
#{item.planStartTime},
#{item.planEndTime},
#{item.realStartTime},#{item.realEndTime},
#{item.projectId},
#{item.fatherTask},#{item.childTask},#{item.isAdd},
#{item.grade},#{item.taskType},#{item.relationTask},
#{item.createTime}
)
</foreach>
</insert>
理解:这里separator中逗号意思如图,自己理解
2.批量修改
2.1
<update id = "saveDeviceTask" parameterType = "java.util.List">
<!-- 批量修改任务 -->
<foreach collection="list" item="item" index="index" separator=";" close="" open="">
update device_task set
SUBJECT = #{item.subject},
STATUS = #{item.status},
OUTPUT = #{item.output},
REMARK = #{item.remark},
PROGRESS = #{item.progress},
PLAN_WORK_TIME = #{item.planWorkTime},
REAL_WORK_TIME = #{item.realWorkTime},
PLAN_DURATION = #{item.planDuration},
REAL_DURATION = #{item.realDuration},
PLAN_START_TIME = #{item.planStartTime},
PLAN_END_TIME = #{item.planEndTime},
REAL_START_TIME = #{item.realStartTime},
REAL_END_TIME = #{item.realEndTime}
<!--PROJECT_ID = #{item.projectId}
FATHER_TASK = #{item.fatherTask},
CHILD_TASK = #{item.childTask}
IS_ADD = #{item.isAdd},
GRADE = #{item.grade},
TASK_TYPE = #{item.taskType},
RELATION_TASK = #{item.relationTask} -->
where ID = #{item.id}
</foreach>
</update>
2.2
<update id ="updateStatusMost" parameterType="java.util.List">
update worktime set status = 1 where id in
(
<foreach collection="list" item="item" separator="," index="">
#{item.id}
</foreach>
)
</update>
3.批量删除
//批量删除:这个List是List<Integer>里面装的是id
<delete id="deleteTaskAndUser" parameterType="java.util.List">
delete task.*,user.* from device_task task
left join device_user user on task.ID = user.TASK_ID
where task.ID in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
#{item.id}
</foreach>
</delete>
4.根据批量id查找
<select id="getJobList" parameterType = "java.util.List" resultType="com.yiyezhiqiu.lyh.domain.Job">
select distinct * from worktime where JOBD in (
<foreach collection="list" item="item" index="index"
separator=",">
#{item.JOBD}
</foreach>
)
</select>