Is it possible to insert a large amount using an annotation?

Asked 2 years ago, Updated 2 years ago, 141 views

Hello, I'm a spring beginner!

I am using mybatis for STS.

Is there any way to put the collection right away using an annotation?

What I want to do is to transfer the following query from the mapper using @Insert to the method as a factor!

INSERT INTO tbname(v1, v2) VALUES (v1 in the first row of the collection, v2 in the first row of the collection), (...), (Last v1, Last v2);

Is there any way to deal with this?

spring mybatis

2022-09-22 22:05

1 Answers

public interface HashcodeMapper {
    @Insert({
        "<script>",
        "INSERT INTO tbname (v1, v2) VALUES ",
        "<foreach collection='list' item='listItem' separator=','>",
        "(#{listItem.v1}, #{listItem.v2})",
        "</foreach>",
        "</script>"
    })
    int insertList(@Param("list") List<Object> list);
}


2022-09-22 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.