为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismapsql

<update id="updateallByEntity" parameterType="java.util.List">
update T_WEEKDAY
<foreach item="item" index="index" collection="list" open="{" separator="," close="}">
<set>
<if test="item.workflag!=null ">
WORKFLAG=#{item.workflag,jdbcType=DECIMAL},
</if>
<if test="item.updateBy!=null ">
UPDATE_BY=#{item.updateBy,jdbcType=VARCHAR},
</if>
<if test="item.updateDate!=null ">
UPDATE_DATE=#{item.updateDate,jdbcType=TIMESTAMP},
</if>
</set>
<where>
<if test="item.weekdayId!=null ">
WEEKDAY_ID=#{item.weekdayId,jdbcType=DECIMAL},
</if>
</where>
</foreach>
</update>

传入的list的值为:
[{updateBy=21, weekdayId=1, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}, {updateBy=21, weekdayId=2, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}, {updateBy=21, weekdayId=3, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}, {updateBy=21, weekdayId=4, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}, {updateBy=21, weekdayId=5, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}, {updateBy=21, weekdayId=6, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=0}, {updateBy=21, weekdayId=7, updateDate=Thu Mar 26 22:36:44 CST 2015, workflag=1}]

报错:
org.springframework.jdbc.UncategorizedSQLException: 
### Error updating database.  Cause: java.sql.SQLException: 出现不支持的 SQL92 标记: 22: 
### The error may involve com.bsth.si.mapper.WeekdayMapper.updateallByEntity-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: 出现不支持的 SQL92 标记: 22: ,具体解决方案如下:

解决方案1:
    UPDATE_DATE=#{item.updateDate,jdbcType=TIMESTAMP},
你第12代码多个逗号吧,
直接把sql打印出来确认一下哪的错误

解决方案2:
Executing: update T_WEEKDAY SET ( WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? ; WORKFLAG=?, UPDATE_BY=?, UPDATE_DATE=? WHERE WEEKDAY_ID=? )

现在是报缺失右括号

map如下:

<update id="updateallByEntity" parameterType="list">
update T_WEEKDAY
<set>
<foreach  item="item" index="key" collection="list" open="(" separator=";" close=")">
WORKFLAG=#{item.workflag,jdbcType=DECIMAL},
UPDATE_BY=#{item.updateBy,jdbcType=VARCHAR},
UPDATE_DATE=#{item.updateDate,jdbcType=TIMESTAMP}
WHERE WEEKDAY_ID=#{item.weekdayId,jdbcType=DECIMAL}
</foreach>
</set>
</update>

求解啊,今天搞了一晚上了!

解决方案3:
http://bbs.csdn.net/topics/380234660
受以上贴子中最后一个人的回复,我解决了我,mybatis中使用foreach,批量update多个对象的问题。在此感谢:ypin2003

其实想通了,就很简单了,只要通过foreach直接把需要的多个update用begin end;包起来就可以实现批量更新了
例如:

<update id="updatesql" >
       <foreach collection="list" item="item" open="begin" separator=";" close=";end;">
        UPDATE  A SET colC = #{item.c} 
            WHERE  (colA = #{item.a} ADN colB = #{item.b})
       </foreach>
</update>

“mybatis 中使用foreach 传的更多相关文章

  1. 基于mysql对mybatis中的foreach进行深入研究

    鉴于上一篇博文一次修改mysql字段类型引发的技术探究提到的,要对foreach里面的collection相关的内容做一些介绍,今天就围绕foreach,做一些数据插入和查询相关的研究. 首先介绍一下 ...

  2. mybatis中的foreach条件参数过多时,#和$效率比较

    在客户端查询都小于1秒. 测试: mybatis中in条件12.3万数据$ : 6051 ms# : 27045 ms 1.2万数据$ : 1154 ms# : 24387 ms 5 万数据$ : 2 ...

  3. Mybatis中的foreach

    <delete id="deleteByParam"> DELETE FROM YZ_SECURITIES_CURRENCY WHERE ID IN <forea ...

  4. mybatis中的foreach方法

    select  t.service_id, t.prod_id, t.prod_name, t.prod_type, t.buss_type, t.pricing_fee, t.detail from ...

  5. Mybatis中的in查询和foreach标签

    Mybatis中的foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separato ...

  6. mybatis中foreach使用

    mybatis中的<foreach collection="list" item="item" index="index" open= ...

  7. mybatis 中 foreach 的性能问题及调优

    1.mybatis中最初的sql语句 SELECT 参数1, 参数2, 参数3 FROM 表 WHERE 条件参数1 in <foreach item="item" inde ...

  8. 谈一下思考,关于mybatis中<foreach collection="list">中list得来的原因 没看到官方说明

    <foreach> 是在sql语句中进行多个id查询 时用到的,因为mybatis代替jdbc和hibernate, 使用 在xml文件中编写sql语句,这是一个标签文件.然后在 dao层 ...

  9. mybatis中foreach的用法(转)

    foreach一共有三种类型,分别为List,[](array),Map三种. foreach属性 属性 描述 item 循环体中的具体对象.支持属性的点路径访问,如item.age,item.inf ...

随机推荐

  1. 【POJ 1981 】Circle and Points

    当两个点距离小于直径时,由它们为弦确定的一个单位圆(虽然有两个圆,但是想一想知道只算一个就可以)来计算覆盖多少点. #include <cstdio> #include <cmath ...

  2. Java套接字

    前言: 本文补充一下Java关于套接字方面的内容,因为其应用相对比较简单,所以下面介绍两个程序实例. ------------------------------------------------- ...

  3. threading示例

    多线程举例: import time import threading def worker(): print ("hello.Kamil") time.sleep(1)#等待一秒 ...

  4. 绘制图形与3D增强技巧(五)----多边形图元的使用及其他

    1.注意多边形图元中的多边形只能是平面的,而且必须为凸多边形,且多边形的边不能弯曲 2.细分和边界,可以人为设置边界边和非边界边 glEdgeFlag(true)//接下来所有点均为边界边起点 glE ...

  5. Redis哈希-hash

    Redis的hash类型数据存储极为重要 hset K V  赋值一个hash 其中V为 (key, value) 127.0.0.1:6379> hset user id 1(integer) ...

  6. Leetcode 114, Flatten Binary Tree to Linked List

    根据提示,本题等价于pre order traverse遍历,并且依次把所有的节点都存成right child,并把left child定义成空集.用递归的思想,那么如果分别把左右子树flatten成 ...

  7. Leetcode # 169, 229 Majority Element I and II

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  8. Webpack打包工具实时更新操作(启用观察者模式)

    可能存在这样的问题,每次修改完js/css文件之后,都要进行手动打包一下,浏览器上刷新一下. 那么我一般这样做: 1.安装Hbuilder,并启用边编辑边看的模式(其实这个是默认的). 2.启动Web ...

  9. Diccuz!NT的dll版本号控制技巧

    dnt每次发布新版本时,公布出来的版本号都是3位数以上,拿3.6.711这个版本号的代码来说,几乎每一个dll上都是统一的版本号命名: 对于一个成熟的产品来说,统一一致的版本号命名有以下的好处: 1. ...

  10. C++开发的基于TCP协议的内网聊天工具

    项目相关地址 源码:https://github.com/easonjim/TCPChat bug提交:https://github.com/easonjim/TCPChat/issues