记得数据源配置allowMultiQueries=true&
不然会报错 -> 添加链接描述
@
目录举例说明
spring.datasource.url=jdbc:mysql://IP:端口/geespace_bd_platform_dev?allowMultiQueries=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&
spring.datasource.username=用户名
spring.datasource.password=密码
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
@Update批量更新
@Update({"<script>",
"<foreach collection='list' item= 'item' index ='index' separator=';'>",
"update ge_data_meta_base set table_size=#{item.dataLength},update_time=now() where id=#{item.id}",
"</foreach>",
"</script>"})
long batchUpdate(@Param("list") List<AssociationTable> list);
@insert批量新增
@Insert("<script>" + "INSERT INTO data_size(size,fileSize,tableSize,userId,date) VALUES"
+ "<foreach collection='dataSizes' item= 'item' index ='index' separator=','>"
+ "(#{item.size},#{item.fileSize},#{item.tableSize},#{item.userId},#{item.date})"
+ "</foreach>" + "</script>")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
long addDataSize(@Param("dataSizes") List<DataSize> dataSizes);
标签:批量,spring,item,datasource,Mybatis,注解,id,size
From: https://www.cnblogs.com/bigcat26/p/18523844