mybatis的批量update操作写法很简单,如下:

public interface YourMapper extends BaseMapper<YourExt> {

    void updateBatch(@Param("pojos") Collection<YourExt> pojos);
}

 

    <update id="updateBatch" parameterType="java.util.Collection">
        <foreach collection="pojos" item = "pojo" separator= ";" >
            update your_table t set pt.your_value = #{pojo.yourValue} where pt.id = #{pojo.id}
        </foreach>
    </update>

在执行过程中报异常,但是sql和参数直接在DB里执行是好的,原因是MySql默认不支持批量更新,需要开发人员主动设置,只需要在你的数据库连接url后面加上

&allowMultiQueries=true

就好了

例如我的数据库连接配置就会变成

mybatis批量update操作的写法,及批量update报错的问题解决方法

 


 
                    
            
                

相关文章:

  • 2022-12-23
  • 2021-10-26
  • 2021-08-05
  • 2021-10-07
  • 2022-12-23
  • 2021-12-29
  • 2021-11-04
猜你喜欢
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案