<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