//單字段的批量更新 如:list存的只有id
/*將前端接收的id集合拼接的字符串解析*/
List<Integer> idList = new ArrayList<Integer>();
idList.add(1);
idList.add(2);
idList.add(3);
/*要修改的信息*/
RoleDO roleDO = new RoleDO();
roleDO.setModifier(baseConditions.getAdminId());
roleDO.setModifyTime(new Date());
roleDO.setIsDeleted(2);
/*Example是where的條件,需要update的主鍵集合List*/
RoleDOExample roleDOExample = new RoleDOExample();
roleDOExample.createCriteria().andIdIn(integerList);
int i = roleDOMapper.updateByExampleSelective(roleDO, roleDOExample);
*sql語句類似
update role set modifier=#{},modify_time =#{},is_deleted=2 where id in(1,3,5);
//多字段的批量更新 如:list存的只有對象
Mapper的接口
int addTeacherClass(@Param("teacherClassesList")List<TeacherClasses> list);
xml的sql
<insert id="addTeacherClass" parameterType="java.util.List">
INSERT into tb_teacher_classes (org_id,teacher_id,class_id,course_id,state)
VALUES
<foreach collection="teacherClassesList" item="item" index="index" separator=",">
(#{item.orgId},#{item.teacherId},#{item.classId},#{item.courseId},#{item.state})
</foreach>
</insert>
逆向工程的Example使用的詳解
https://blog.csdn.net/biandous/article/details/65630783