mytatis foreach 下面的update用法

任第一 2013-02-21 01:39:08
<update id="id" parameterType="Dto">
<foreach item="item" collection="是一个list" >
update test set t.A=#{item.a},t.b='success' where t.id=#{item.id}
</foreach>
</update>

我想这么写。但是报错。假如list里面有两条记录打印Sql如下:
update test set t.A=a,t.b='success' where t.id=1 update test set t.A=a1,t.b='success' where t.id=2

mybatis 中的Sql是不能这么写的。希望大家给我一个思路。
...全文
742 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
基本要牢靠 2013-02-26
  • 打赏
  • 举报
回复
我们连sqlserver,mybatis的批量更新写的和你一样,只是{item.a,jdbcType=?} 更新我不知道,批量插入如果不写jdbcType 会报错
任第一 2013-02-21
  • 打赏
  • 举报
回复
引用 2 楼 itdongtian 的回复:
错误贴出来啊
错误就是他把两个update语句拼起来,就发给Oracle了。oracle 肯定不识别,不是循环完一次就发给oracle,循环完第二次就发给oracle。
任第一 2013-02-21
  • 打赏
  • 举报
回复
引用 3 楼 suciver 的回复:
这个必须报错。update test t set t.A=a,t.b='success' where t.id=1。这里的t是什么要是给test的别名的话不能这么写
不好意思写错了。
suciver 2013-02-21
  • 打赏
  • 举报
回复
这个必须报错。update test set t.A=a,t.b='success' where t.id=1。这里的t是什么要是给test的别名的话不能这么写
基本要牢靠 2013-02-21
  • 打赏
  • 举报
回复
错误贴出来啊
evang_shot 2013-02-21
  • 打赏
  • 举报
回复
加一个<if test=""><if>进行判断,这样不知道行不行

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧