前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mybatis批量update的时候失败,解决办法

mybatis批量update的时候失败,解决办法

作者头像
凯哥Java
发布2022-12-15 15:26:11
7640
发布2022-12-15 15:26:11
举报
文章被收录于专栏:凯哥Java凯哥Java

mybatis批量更新:

形式一:

更新的时候带有判断条件的:

代码语言:javascript
复制
<!-- 添加数据权限后,数据补充。批量更新入库 -->
<update id="batechUpdateInfoForOaAuth" parameterType="list">
      <foreach collection="aList"   index="index" item="item" open="" close="" separator=";">
          update a表
          <set>
              <if test="item.deptCode !=null">
                  dept_code = #{item.deptCode,jdbcType=VARCHAR},
              </if>

              <if test="item.deptName !=null">
                  dept_name = #{item.deptName,jdbcType=VARCHAR},
              </if>


              <if test="item.productLineCode !=null">
                  product_line_code = #{item.productLineCode,jdbcType=VARCHAR},
              </if>

              <if test="item.productLineName !=null">
                  product_line_name = #{item.productLineName,jdbcType=VARCHAR},
              </if>

              <if test="item.subjectCode !=null">
                  subject_code = #{item.subjectCode,jdbcType=VARCHAR},
              </if>

              <if test="item.subjectName !=null">
                  subject_name = #{item.subjectName,jdbcType=VARCHAR},
              </if>

              <if test="item.jobDeptCode !=null">
                  job_dept_code = #{item.jobDeptCode,jdbcType=VARCHAR},
              </if>

              <if test="item.jobDeptName !=null">
                  job_dept_name = #{item.jobDeptName,jdbcType=VARCHAR},
              </if>

              <if test="item.jobManagerName !=null">
                  job_manager_name = #{item.jobManagerName,jdbcType=VARCHAR},
              </if>

              <if test="item.financeType !=null">
                  finance_type = #{item.financeType},
              </if>
          </set>
          where id = #{item.id}
      </foreach>
</update>
25b30813a065c18391f6c6e65938f4d0.png
25b30813a065c18391f6c6e65938f4d0.png

形式二:直接更新

代码语言:javascript
复制
<!--添加数据权限后,结算数据补充。批量更新入库-->
<update id="batechUpdateSalarWayInfoForOaAuth" parameterType="java.util.List">
    <foreach collection="bWayList" item="item" index="index"  open="" close="" separator=";">
        update b表
        <set>
            position_type = ${item.positionType}
        </set>
          where id = ${item.id}
    </foreach>
</update>
2500e7a3868924c788da19c2308acda2.png
2500e7a3868924c788da19c2308acda2.png

如果直接这样写,有可能会出现问题的。因为:

<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true" />  

数据库连接需要添加:allowMultiQueries=true

有可能是下面这种情况:

7ec7733e33d68a6656179b42cedd2e66.png
7ec7733e33d68a6656179b42cedd2e66.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-01-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档