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