今天学会了使用java 批量插入的语句

在mapper.xml里边写入语句(此处注意在最后一个变量后面不要加,否则数据库无法执行sql语句)
注意引用mapper的java文件时要引入正确(这种错误以后就不要再犯了)
< insert id=“insertCodeBatch” parameterType=“java.util.List”>
insert into t_thing_releation
(from_thing_type,from_thing_id,to_thing_type,to_thing_id)
values
< foreach collection=“list” item=“ThingReleation” index=“index” separator=",">
(
#{ThingReleation.fromThingType}, #{ThingReleation.fromThingId},
#{ThingReleation.toThingType}, #{ThingReleation.toThingId}
)
< /foreach>
< /insert>
在mapper.java里边写入语句
int insertCodeBatch(List< ThingReleation > thingReleationList);

猜你喜欢

转载自blog.csdn.net/qq_44866462/article/details/89021959