mybatis传入List实现批量更新的坑
2024-10-09 10:37:54
原文: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>
最新文章
- SQL Server数据阻塞原因
- java获取对象属性类型、属性名称、属性值
- 关于c#的一些笔记
- http请求详解
- 海量字符串查找——bloom filter,c
- Makefile所有内嵌函数
- 写给新入IT的新人们
- iOS开发——企业证书(免审核 299$)
- JS+CSS实现选项卡功能
- BZOJ 1013 球形空间产生器
- sql server 2005中IMAGE类型的BUG问题
- linux内核基础(系统调用,简明)
- 我和Python的Py交易》》》》》》 浮点数的身世字谜
- Connection reset by [server_ip] port 22 (hexo d 部署博客出错)
- 线段树 HDU-1166 敌兵布阵
- Go并发控制--context的使用
- Java http请求工具类
- 【代码笔记】iOS-给密码进行加密
- ActiveMQ 基于zookeeper的主从(levelDB Master/Slave)搭建以及Spring-boot下使用
- 不同数据库的driverClassName与url
热门文章
- 测试开发之Django——No8.Django中的视图与URL配置
- hdu4812 逆元+树分治
- 利用反射创建User类的对象
- selenium+python谷歌驱动配置
- each()遍历
- java中final,finally,finalize三个关键字的区别
- 线程池 多线程运行结束后 如何关闭? ExecutorService的正确关闭方法
- git shell 命令大全
- Linux 僵尸进程的筛选和查杀
- pyqt5 &#39;QWidget&#39; object has no attribute &#39;setCentralWidget&#39;(转)