zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    求解答可用性测试记
    Teambition可用性测试记
    海丁网可用性测试记
    go语言的切片
    go语言的数组
    go语言的函数
    go语言的接口
    go语言的结构体
    go语言的flag
    创建二叉树和三种遍历
  • 原文地址:https://www.cnblogs.com/draymond/p/10327819.html
Copyright © 2011-2022 走看看