原文: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>

最新文章

  1. SQL Server数据阻塞原因
  2. java获取对象属性类型、属性名称、属性值
  3. 关于c#的一些笔记
  4. http请求详解
  5. 海量字符串查找——bloom filter,c
  6. Makefile所有内嵌函数
  7. 写给新入IT的新人们
  8. iOS开发——企业证书(免审核 299$)
  9. JS+CSS实现选项卡功能
  10. BZOJ 1013 球形空间产生器
  11. sql server 2005中IMAGE类型的BUG问题
  12. linux内核基础(系统调用,简明)
  13. 我和Python的Py交易》》》》》》 浮点数的身世字谜
  14. Connection reset by [server_ip] port 22 (hexo d 部署博客出错)
  15. 线段树 HDU-1166 敌兵布阵
  16. Go并发控制--context的使用
  17. Java http请求工具类
  18. 【代码笔记】iOS-给密码进行加密
  19. ActiveMQ 基于zookeeper的主从(levelDB Master/Slave)搭建以及Spring-boot下使用
  20. 不同数据库的driverClassName与url

热门文章

  1. 测试开发之Django——No8.Django中的视图与URL配置
  2. hdu4812 逆元+树分治
  3. 利用反射创建User类的对象
  4. selenium+python谷歌驱动配置
  5. each()遍历
  6. java中final,finally,finalize三个关键字的区别
  7. 线程池 多线程运行结束后 如何关闭? ExecutorService的正确关闭方法
  8. git shell 命令大全
  9. Linux 僵尸进程的筛选和查杀
  10. pyqt5 &#39;QWidget&#39; object has no attribute &#39;setCentralWidget&#39;(转)