1、批量添加
<!-- 批量插入活动表--><insert id="insertBatchActivity">
INSERT INTO activity
(
activity_id, user_id, create_time
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.activityId},
#{item.userId},
now()
)
</foreach>
</insert>
2、批量更新
在mybatis的xml文件中,使用foreach动态标签拼接SQL语句,每一条数据的更新语句对应一条update语句,多条语句最终使用";"号进行拼接。
<update id="updateBatchById"><foreach collection="list" item="item" separator=";">
update
t_student
set
name
= #{item.name},
age
= #{item.age}where
id = #{item.id}
</foreach>
</update>
—补充
Cause: java.sql.SQLException: sql injection violation, multi-statement not allow : update ipplus360_mall.users_library_version_authority set shew =?,updated_time =?where user_id=? and library_version = ?
解决方法
spring.datasource.druid.filters=config,wall,slf4j
spring.datasource.druid.filters=config,slf4j
spring.datasource.url = jdbc:mysql://127.0.0.1:3306/test?useSSL=false&zeroDateTimeBehavior=convertToNull&autoReconnect=true&allowMultiQueries=true&characterEncoding=UTF-8&characterSetResults=UTF-8