mybatis 批量插入


//单字段的批量更新  如: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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM