zoukankan      html  css  js  c++  java
  • mybatis传入List实现批量更新的坑

    原文:http://www.cnblogs.com/zzlback/p/9342329.html

    今天用mybatis实现批量更新,一直报错,说我的sql语句不对,然后我还到mysql下面试了,明明没问题,但就是过不去,原来问题在这。

    在连接数据库的url中要加入?allowMultiQueries=true这段,而且要放在第一行

     然后dao层就如下写

    最后mapper.xml就是正常的写法,解释一下,我的collection="list",为什么写list,因为传入的是一个list集合,这里必须写list,

    如果传入一个数组比如Integer[],那么就要写collection="array"

    <!-- 如果不是第一次参加考试,就更新学生的答案 -->
        <update id="updateStudentAnswer" parameterType="java.util.List">
            <if test="list!=null">
                <foreach collection="list" item="studentAnswer" index= "index" open="" close="" separator =";">
                    update studentanswerinfo
                    <set>
                        SAnswer=#{studentAnswer.SAnswer},
                        Getpoint=#{studentAnswer.Getpoint},
                        other=#{studentAnswer.other}
                    </set>
                    <where>
                        questionID=#{studentAnswer.questionID}
                    </where>
                </foreach>
            </if>
        </update>
  • 相关阅读:
    学习
    2018年看书计划(40本)
    java快排(两种方法)
    max-points-on-a-line
    Angular不同版本对应的Bootstrap组件
    AngularCLI介绍及配置文件主要参数含义解析
    D3——Updates, Transitions, and Motion
    SVG中的元素属性
    D3——Axes
    Angular2.0知识架构图
  • 原文地址:https://www.cnblogs.com/shihaiming/p/10341293.html
Copyright © 2011-2022 走看看