美文网首页
Mybatis批量更新报错Unexpected error oc

Mybatis批量更新报错Unexpected error oc

作者: ggr | 来源:发表于2018-05-05 17:15 被阅读0次

今天发版测试遇到一个恶心的问题,mybatis批量更新异常,百度解决


image.png

解决方案:
http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html#foreach

简单点就是把list方式传参换做map传参,其他不变。

 @Override
    public int saveUserInfo(List<UserInfoDo> userInfoList) {
        if(CollectionUtils.isEmpty(userInfoList)){
            return 0;
        }else{
            Map<String,Object> map = new HashMap<>();
            map.put("userInfoList",userInfoList);
           userInfoDoMapper.updateUserInfoDos(userInfoList);
           log.info("批量更新数据userInfoList={}",userInfoList);
            return userInfoList.size();
        }
    }

xml配合改一下

  <!-- 批量更新用户信息 -->
  <update id="updateUserInfoDos" parameterType="java.util.List">
    <foreach collection="userInfoList" item="item" index="index" open="" close="" separator=";">
      update t_cmb_fintech_user_info
      <set>
        <if test="userName != null" >
          user_name = #{item.userName,jdbcType=VARCHAR},
        </if>
        <if test="userProbability != null" >
          user_probability = #{item.userProbability,jdbcType=DOUBLE},
        </if>
        <if test="userSpare != null" >
          user_spare = #{item.userSpare,jdbcType=VARCHAR},
        </if>
        <if test="userShareCount != null" >
          user_share_count = #{item.userShareCount,jdbcType=INTEGER},
        </if>
        <if test="userShareNum != null" >
          user_share_num = #{item.userShareNum,jdbcType=INTEGER},
        </if>
      </set>
      where user_uid = #{item.userUid,jdbcType=VARCHAR}
    </foreach>
  </update>
  

相关文章

网友评论

      本文标题:Mybatis批量更新报错Unexpected error oc

      本文链接:https://www.haomeiwen.com/subject/krrerftx.html