MyBatis Batch Insert/Update Using Annotations

Satish Mahadevan picture Satish Mahadevan · Dec 16, 2015 · Viewed 7.5k times · Source

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

Answer

Persia picture Persia · Jan 3, 2016

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);