Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MyBatis Batch Insert/Update Using Annotations

Please let me know, how to perform batch insert/update in mybatis using annotated mappers.

like image 866
Satish Mahadevan Avatar asked Dec 19 '22 21:12

Satish Mahadevan


1 Answers

you can do it like this:

@Insert({
            "<script>",
            "insert into mybatis_demo (name, age)",
            "values ",
            "<foreach  collection='dmoList' item='dmo' separator=','>",
            "( #{dmo.name,jdbcType=VARCHAR}, #{dmo.age,jdbcType=INTEGER})",
            "</foreach>",
            "</script>"
    })
    int insertBatch(@Param("dmoList") List<MybatisDemoDMO> dmoList);
like image 85
Persia Avatar answered Jan 08 '23 18:01

Persia