代码改变世界

mybaties批量更新无法进行

2019-05-02 16:53  CCG波克  阅读(348)  评论(0编辑  收藏  举报

<update id="updateEvaluteStateByList" parameterType="java.util.List">
<if test="list!=null">
<foreach collection="list" item="item" index= "index" separator =";">
update tb_flags
<set>
opioid_evaluate_flag = 0
</set>
<where>
id = #{item.id,jdbcType=INTEGER}
</where>
</foreach>
</if>
</update>

更新一条可以更新多条不行

再次之前写了批量插入

<!-- 批量插入 -->
<insert id="insertForeach" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="nonOpioidId">
INSERT INTO tb_non_opioid ( assess_id, non_opioid_name, first_use_time, method_use, rate, weekly_use )
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.assessId,jdbcType=BIGINT},
#{item.nonOpioidName,jdbcType=VARCHAR},
#{item.firstUseTime,jdbcType=TIMESTAMP},
#{item.methodUse,jdbcType=VARCHAR},
#{item.rate,jdbcType=DOUBLE},
#{item.weeklyUse,jdbcType=DOUBLE}
)
</foreach>
</insert>

是可以的

修改数据库配置

# allowMultiQueries=true 允许批量
spring.datasource.url=jdbc:mysql://47.106.82.158:3306/addict?characterEncoding=utf-8&serverTimezone=CTT&allowMultiQueries=true